diff --git a/Cargo.lock b/Cargo.lock index 829cf08..bd051b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -241,7 +241,6 @@ version = "0.21.2" dependencies = [ "base64 0.22.1", "cookie 0.18.1", - "fantoccini", "futures-core", "futures-util", "http 1.1.0", diff --git a/Cargo.toml b/Cargo.toml index 4d3f379..803f2e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ license = "MIT OR Apache-2.0" default = ["native-tls"] native-tls = ["hyper-tls", "openssl"] rustls-tls = ["hyper-rustls"] -test_helpers = [] [dependencies] webdriver = { version = "0.50", default-features = false } @@ -48,7 +47,6 @@ tokio = { version = "1", features = ["full"] } hyper = { version = "1.1.0", features = ["server"] } hyper-util = { version = "0.1.3", features = ["server", "http1"] } serial_test = "3.0" -fantoccini = { path = "../fantoccini", features = ["test_helpers"] } # for minimal-versions [target.'cfg(any())'.dependencies] diff --git a/src/lib.rs b/src/lib.rs index b2d125b..9cfd098 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -266,6 +266,3 @@ pub mod wait; pub mod wd; #[doc(inline)] pub use wd::Locator; - -#[cfg(any(test, feature = "test_helpers"))] -pub use crate::session::test_wrap_command; diff --git a/src/session.rs b/src/session.rs index 10ec7a5..d24d10f 100644 --- a/src/session.rs +++ b/src/session.rs @@ -30,18 +30,6 @@ type Wcmd = WebDriverCommand; #[derive(Debug)] struct WcmdWrapper(Wcmd); -/// Wraps a WebDriverCommand inside a WcmdWrapper and returns it as a -/// Box. -/// -/// This helper function is intended for use in tests where internal -/// WebDriver commands need to be wrapped in the private `WcmdWrapper` -#[cfg(any(test, feature = "test_helpers"))] -pub fn test_wrap_command( - cmd: WebDriverCommand, -) -> Box { - Box::new(WcmdWrapper(cmd)) -} - #[allow(clippy::large_enum_variant)] #[derive(Debug)] pub(crate) enum Cmd { @@ -350,9 +338,9 @@ impl Client { /// Issue the specified [`WebDriverCompatibleCommand`] to the WebDriver instance. pub async fn issue_cmd( &self, - cmd: Box, + cmd: impl Into>, ) -> Result { - self.issue(Cmd::WebDriver(cmd)).await + self.issue(Cmd::WebDriver(cmd.into())).await } pub(crate) fn is_legacy(&self) -> bool { diff --git a/tests/local.rs b/tests/local.rs index 0d1bfe2..c34a74f 100644 --- a/tests/local.rs +++ b/tests/local.rs @@ -1,16 +1,49 @@ //! Tests that don't make use of external websites. use crate::common::{other_page_url, sample_page_url}; -use fantoccini::wd::TimeoutConfiguration; -use fantoccini::{error, test_wrap_command, Client, Locator}; +use fantoccini::wd::{TimeoutConfiguration, WebDriverCompatibleCommand}; +use fantoccini::{error, Client, Locator}; use http_body_util::BodyExt; use hyper::Method; use serial_test::serial; use std::time::Duration; use url::Url; -use webdriver::command::WebDriverCommand; mod common; +#[derive(Debug)] +struct GetTitle; + +// Implement `WebDriverCompatibleCommand` for `GetTitle` +impl WebDriverCompatibleCommand for GetTitle { + fn endpoint( + &self, + base_url: &url::Url, + session_id: Option<&str>, + ) -> Result { + let base = base_url.join(&format!("session/{}/", session_id.unwrap()))?; + base.join("title") + } + + fn method_and_body(&self, _: &url::Url) -> (http::Method, Option) { + (http::Method::GET, None) + } + + fn is_new_session(&self) -> bool { + false + } + + fn is_legacy(&self) -> bool { + false + } +} + +// Implement `Into>` for `GetTitle` +impl Into> for GetTitle { + fn into(self) -> Box { + Box::new(self) + } +} + async fn goto(c: Client, port: u16) -> Result<(), error::CmdError> { let url = sample_page_url(port); c.goto(&url).await?; @@ -423,13 +456,9 @@ async fn timeouts(c: Client, _: u16) -> Result<(), error::CmdError> { async fn dynamic_commands(c: Client, port: u16) -> Result<(), error::CmdError> { let sample_url = sample_page_url(port); c.goto(&sample_url).await?; - let title = c - .issue_cmd(test_wrap_command(WebDriverCommand::GetTitle)) - .await?; + let title = c.issue_cmd(GetTitle).await?; assert_eq!(title.as_str(), Some("Sample Page")); - let title = c - .issue_cmd(test_wrap_command(WebDriverCommand::GetTitle)) - .await?; + let title = c.issue_cmd(GetTitle).await?; assert_eq!(title.as_str(), Some("Sample Page")); Ok(()) }