Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrtgs committed Oct 22, 2024
2 parents b0351a3 + ef188b9 commit fa6e089
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added thirtyfour/.DS_Store
Binary file not shown.
12 changes: 12 additions & 0 deletions thirtyfour/src/common/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
use const_format::formatcp;
use http::HeaderValue;
use std::sync::Arc;
use std::time::Duration;

/// Configuration options used by a `WebDriver` instance and the related `SessionHandle`.
///
Expand All @@ -19,6 +20,8 @@ pub struct WebDriverConfig {
pub poller: Arc<dyn IntoElementPoller + Send + Sync>,
/// The user agent to use when sending commands to the webdriver server.
pub user_agent: HeaderValue,
/// The timeout duration for reqwest client requests.
pub reqwest_timeout: Duration,
}

impl Default for WebDriverConfig {
Expand Down Expand Up @@ -68,6 +71,7 @@ pub struct WebDriverConfigBuilder {
keep_alive: bool,
poller: Option<Arc<dyn IntoElementPoller + Send + Sync>>,
user_agent: Option<WebDriverResult<HeaderValue>>,
reqwest_timeout: Duration,
}

impl Default for WebDriverConfigBuilder {
Expand All @@ -83,6 +87,7 @@ impl WebDriverConfigBuilder {
keep_alive: true,
poller: None,
user_agent: None,
reqwest_timeout: Duration::from_secs(120),
}
}

Expand All @@ -108,12 +113,19 @@ impl WebDriverConfigBuilder {
self
}

/// Set the reqwest timeout.
pub fn reqwest_timeout(mut self, timeout: Duration) -> Self {
self.reqwest_timeout = timeout;
self
}

/// Build `WebDriverConfig` using builder options.
pub fn build(self) -> WebDriverResult<WebDriverConfig> {

Check warning on line 123 in thirtyfour/src/common/config.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large

warning: the `Err`-variant returned from this function is very large --> thirtyfour/src/common/config.rs:123:27 | 123 | pub fn build(self) -> WebDriverResult<WebDriverConfig> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ::: thirtyfour/src/error.rs:137:5 | 137 | NotInSpec(WebDriverErrorInfo), | ----------------------------- the largest variant contains at least 176 bytes 138 | #[error("The click event was intercepted by another element: {0}")] 139 | ElementClickIntercepted(WebDriverErrorInfo), | ------------------------------------------- the variant `ElementClickIntercepted` contains at least 176 bytes 140 | #[error("The element is not interactable: {0}")] 141 | ElementNotInteractable(WebDriverErrorInfo), | ------------------------------------------ the variant `ElementNotInteractable` contains at least 176 bytes 142 | #[error("The certificate is insecure: {0}")] 143 | InsecureCertificate(WebDriverErrorInfo), | --------------------------------------- the variant `InsecureCertificate` contains at least 176 bytes 144 | #[error("An argument passed to the WebDriver server was invalid: {0}")] 145 | InvalidArgument(WebDriverErrorInfo), | ----------------------------------- the variant `InvalidArgument` contains at least 176 bytes ... 149 | InvalidCookieDomain(WebDriverErrorInfo), | --------------------------------------- the variant `InvalidCookieDomain` contains at least 176 bytes 150 | #[error("The element is in an invalid state: {0}")] 151 | InvalidElementState(WebDriverErrorInfo), | --------------------------------------- the variant `InvalidElementState` contains at least 176 bytes 152 | #[error("The specified element selector is invalid: {0}")] 153 | InvalidSelector(WebDriverErrorInfo), | ----------------------------------- the variant `InvalidSelector` contains at least 176 bytes 154 | #[error("The WebDriver session id is invalid: {0}")] 155 | InvalidSessionId(WebDriverErrorInfo), | ------------------------------------ the variant `InvalidSessionId` contains at least 176 bytes 156 | #[error("The Javascript code returned an error: {0}")] 157 | JavascriptError(WebDriverErrorInfo), | ----------------------------------- the variant `JavascriptError` contains at least 176 bytes 158 | #[error("Unable to scroll the element into the viewport: {0}")] 159 | MoveTargetOutOfBounds(WebDriverErrorInfo), | ----------------------------------------- the variant `MoveTargetOutOfBounds` contains at least 176 bytes 160 | #[error("Alert not found: {0}")] 161 | NoSuchAlert(WebDriverErrorInfo), | ------------------------------- the variant `NoSuchAlert` contains at least 176 bytes 162 | #[error("Cookie not found: {0}")] 163 | NoSuchCookie(WebDriverErrorInfo), | -------------------------------- the variant `NoSuchCookie` contains at least 176 bytes 164 | #[error("Element not found: {0}")] 165 | NoSuchElement(WebDriverErrorInfo), | --------------------------------- the variant `NoSuchElement` contains at least 176 bytes 166 | #[error("Frame not found: {0}")] 167 | NoSuchFrame(WebDriverErrorInfo), | ------------------------------- the variant `NoSuchFrame` contains at least 176 bytes 168 | #[error("Window not found: {0}")] 169 | NoSuchWindow(WebDriverErrorInfo), | -------------------------------- the variant `NoSuchWindow` contains at least 176 bytes 170 | #[error("The Javascript code did not complete within the script timeout (see WebDriver::set_script_timeout()): {0}")] 171 | ScriptTimeout(WebDriverErrorInfo), | --------------------------------- the variant `ScriptTimeout` contains at least 176 bytes 172 | #[error("Unable to create WebDriver session: {0}")] 173 | SessionNotCreated(WebDriverErrorInfo), | ------------------------------------- the variant `SessionNotCreated` contains at least 176 bytes 174 | #[error("Element is stale: {0}")] 175 | StaleElementReference(WebDriverErrorInfo), | ----------------------------------------- the variant `StaleElementReference` contains at least 176 bytes 176 | #[error("Operation timed out: {0}")] 177 | WebDriverTimeout(WebDriverErrorInfo), | ------------------------------------ the variant `WebDriverTimeout` contains at least 176 bytes 178 | #[error("Unable to set cookie: {0}")] 179 | UnableToSetCookie(WebDriverErrorInfo), | ------------------------------------- the variant `UnableToSetCookie` contains at least 176 bytes 180 | #[error("Unable to capture screenshot: {0}")] 181 | UnableToCaptureScreen(WebDriverErrorInfo), | ----------------------------------------- the variant `UnableToCaptureScreen` contains at least 176 bytes 182 | #[error("An unexpected alert is currently open: {0}")] 183 | UnexpectedAlertOpen(WebDriverErrorInfo), | --------------------------------------- the variant `UnexpectedAlertOpen` contains at least 176 bytes 184 | #[error("Unknown command: {0}")] 185 | UnknownCommand(WebDriverErrorInfo), | ---------------------------------- the variant `UnknownCommand` contains at least 176 bytes 186 | #[error("Unknown error: {0}")] 187 | UnknownError(WebDriverErrorInfo), | -------------------------------- the variant `UnknownError` contains at least 176 bytes 188 | #[error("Unknown method: {0}")] 189 | UnknownMethod(WebDriverErrorInfo), | --------------------------------- the variant `UnknownMethod` contains at least 176 bytes 190 | #[error("Unsupport operation: {0}")] 191 | UnsupportedOperation(WebDriverErrorInfo), | ---------------------------------------- the variant `UnsupportedOperation` contains at least 176 bytes | = help: try reducing the size of `error::WebDriverError`, for example by boxing large elements or replacing it with `Box<error::WebDriverError>` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
Ok(WebDriverConfig {
keep_alive: self.keep_alive,
poller: self.poller.unwrap_or_else(|| Arc::new(ElementPollerWithTimeout::default())),
user_agent: self.user_agent.transpose()?.unwrap_or(WebDriverConfig::DEFAULT_USER_AGENT),
reqwest_timeout: self.reqwest_timeout,
})
}
}
4 changes: 2 additions & 2 deletions thirtyfour/src/web_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ impl WebDriver {
S: Into<String>,
C: Into<Capabilities>,
{
// TODO: create builder and make timeout configurable.
// TODO: create builder
#[cfg(feature = "reqwest")]
let client = create_reqwest_client(std::time::Duration::from_secs(120));
let client = create_reqwest_client(config.reqwest_timeout);
#[cfg(not(feature = "reqwest"))]
let client = crate::session::http::null_client::create_null_client();
Self::new_with_config_and_client(server_url, capabilities, config, client).await
Expand Down

0 comments on commit fa6e089

Please sign in to comment.