-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Encapsulate Wcmd
within a private wrapper
#275
base: main
Are you sure you want to change the base?
Changes from 4 commits
07a72b9
6c19c80
f3d43da
e26d58e
0dd402d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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::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<url::Url, url::ParseError> { | ||
let base = base_url.join(&format!("session/{}/", session_id.unwrap()))?; | ||
base.join("title") | ||
} | ||
|
||
fn method_and_body(&self, _: &url::Url) -> (http::Method, Option<String>) { | ||
(http::Method::GET, None) | ||
} | ||
|
||
fn is_new_session(&self) -> bool { | ||
false | ||
} | ||
|
||
fn is_legacy(&self) -> bool { | ||
false | ||
} | ||
} | ||
|
||
// Implement `Into<Box<dyn WebDriverCompatibleCommand + Send>>` for `GetTitle` | ||
impl Into<Box<dyn WebDriverCompatibleCommand + Send>> for GetTitle { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if you use exactly the version of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to use
To avoid using nested There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, that just means you'll need to use "proper" generics instead: <C, CC> where C: Into<Box<CC>>, CC: WebDriverCompatibleCommand + Send + 'static There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, got it. Using |
||
fn into(self) -> Box<dyn WebDriverCompatibleCommand + Send> { | ||
Box::new(self) | ||
} | ||
} | ||
|
||
async fn goto(c: Client, port: u16) -> Result<(), error::CmdError> { | ||
let url = sample_page_url(port); | ||
c.goto(&url).await?; | ||
|
@@ -423,9 +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(WebDriverCommand::GetTitle).await?; | ||
let title = c.issue_cmd(GetTitle).await?; | ||
assert_eq!(title.as_str(), Some("Sample Page")); | ||
let title = c.issue_cmd(Box::new(WebDriverCommand::GetTitle)).await?; | ||
let title = c.issue_cmd(GetTitle).await?; | ||
assert_eq!(title.as_str(), Some("Sample Page")); | ||
Ok(()) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add default implementations for the two
is_
methods directly on the trait?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I'll make the update in the next commit.