Skip to content

Commit

Permalink
Merge pull request #245 from bylerbk/configurable-client-timeout
Browse files Browse the repository at this point in the history
Allowing users of the library to tweak the reqwest client's timeout
  • Loading branch information
Vrtgs authored Oct 21, 2024
2 parents 7962b59 + 4ca5507 commit ef188b9
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> {
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 ef188b9

Please sign in to comment.