siderunner/command/
assert_alert.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5use super::Command;
6use crate::{error::RunnerErrorKind, webdriver::Webdriver};
7
8pub struct AssertAlert {
9    text: String,
10}
11
12impl AssertAlert {
13    pub fn new(text: String) -> Self {
14        Self { text }
15    }
16}
17
18#[async_trait::async_trait]
19impl<D: Webdriver> Command<D> for AssertAlert {
20    async fn run(&self, runner: &mut crate::runner::Runner<D>) -> Result<(), RunnerErrorKind> {
21        let alert = runner.get_webdriver().alert_text().await?;
22
23        if alert == self.text {
24            Ok(())
25        } else {
26            Err(RunnerErrorKind::AssertFailed {
27                lhs: alert,
28                rhs: self.text.clone(),
29            })
30        }
31    }
32}