Skip to main content

chrome_for_testing_manager/
session.rs

1use crate::ChromeForTestingManagerError;
2use rootcause::Report;
3use rootcause::prelude::ResultExt;
4
5/// A browser session. Used to control the browser.
6///
7/// When using `thirtyfour` (feature), this has a `Deref` impl to `thirtyfour::WebDriver`, so this
8/// session can be seen as the `driver`.
9#[derive(Debug)]
10pub struct Session {
11    pub(crate) driver: thirtyfour::WebDriver,
12}
13
14impl Session {
15    /// Quit the browser session.
16    ///
17    /// # Errors
18    ///
19    /// Returns an error if the underlying `WebDriver` session cannot be closed.
20    pub(crate) async fn quit(self) -> Result<(), Report<ChromeForTestingManagerError>> {
21        self.driver
22            .quit()
23            .await
24            .context(ChromeForTestingManagerError::QuitSession)
25    }
26}
27
28impl std::ops::Deref for Session {
29    type Target = thirtyfour::WebDriver;
30
31    fn deref(&self) -> &Self::Target {
32        &self.driver
33    }
34}