Skip to content
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

Allowing users of the library to tweak the reqwest client's timeout #245

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 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,20 @@ 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
})
}
}
5 changes: 3 additions & 2 deletions thirtyfour/src/web_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ 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
Loading