chrome_for_testing_manager/
session.rs

1use thiserror::Error;
2
3/// A browser session. Used to control the browser.
4///
5/// When using `thirtyfour` (feature), this has a `Deref` impl to `thirtyfour::WebDriver`, so this
6/// session can be seen as the `driver`.
7#[derive(Debug)]
8pub struct Session {
9    #[cfg(feature = "thirtyfour")]
10    pub(crate) driver: thirtyfour::WebDriver,
11}
12
13#[derive(Debug, Error)]
14pub enum SessionError {
15    #[error("The user code panicked:\n{reason}")]
16    Panic {
17        reason: String
18    },
19
20    #[cfg(feature = "thirtyfour")]
21    #[error("thirtyfour WebDriverError")]
22    Thirtyfour {
23        #[from]
24        source: thirtyfour::error::WebDriverError,
25    },
26}
27
28impl Session {
29    pub async fn quit(self) -> Result<(), SessionError> {
30        #[cfg(feature = "thirtyfour")]
31        {
32            self.driver.quit().await.map_err(Into::into)
33        }
34
35        #[cfg(not(feature = "thirtyfour"))]
36        {
37            unimplemented!()
38        }
39    }
40}
41
42#[cfg(feature = "thirtyfour")]
43impl std::ops::Deref for Session {
44    type Target = thirtyfour::WebDriver;
45
46    fn deref(&self) -> &Self::Target {
47        &self.driver
48    }
49}