use std::time::Duration;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, strum::EnumString, strum::Display)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum WebDriverBrowser {
#[default]
#[cfg_attr(feature = "serde", serde(rename = "chrome"))]
Chrome,
#[cfg_attr(feature = "serde", serde(rename = "firefox"))]
Firefox,
#[cfg_attr(feature = "serde", serde(rename = "edge"))]
Edge,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WebDriverConfig {
pub server_url: String,
pub browser: WebDriverBrowser,
pub headless: bool,
pub browser_args: Option<Vec<String>>,
pub timeout: Option<Duration>,
pub proxy: Option<String>,
pub user_agent: Option<String>,
pub viewport_width: Option<u32>,
pub viewport_height: Option<u32>,
pub accept_insecure_certs: bool,
pub page_load_strategy: Option<String>,
}
impl Default for WebDriverConfig {
fn default() -> Self {
Self {
server_url: "http://localhost:4444".to_string(),
browser: WebDriverBrowser::Chrome,
headless: true,
browser_args: None,
timeout: Some(Duration::from_secs(60)),
proxy: None,
user_agent: None,
viewport_width: None,
viewport_height: None,
accept_insecure_certs: false,
page_load_strategy: None,
}
}
}
impl WebDriverConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_server_url(mut self, server_url: impl Into<String>) -> Self {
self.server_url = server_url.into();
self
}
pub fn with_browser(mut self, browser: WebDriverBrowser) -> Self {
self.browser = browser;
self
}
pub fn with_headless(mut self, headless: bool) -> Self {
self.headless = headless;
self
}
pub fn with_browser_args(mut self, args: Vec<String>) -> Self {
self.browser_args = Some(args);
self
}
pub fn with_timeout(mut self, timeout: Duration) -> Self {
self.timeout = Some(timeout);
self
}
pub fn with_proxy(mut self, proxy: impl Into<String>) -> Self {
self.proxy = Some(proxy.into());
self
}
pub fn with_user_agent(mut self, user_agent: impl Into<String>) -> Self {
self.user_agent = Some(user_agent.into());
self
}
pub fn with_viewport(mut self, width: u32, height: u32) -> Self {
self.viewport_width = Some(width);
self.viewport_height = Some(height);
self
}
pub fn with_accept_insecure_certs(mut self, accept: bool) -> Self {
self.accept_insecure_certs = accept;
self
}
pub fn with_page_load_strategy(mut self, strategy: impl Into<String>) -> Self {
self.page_load_strategy = Some(strategy.into());
self
}
pub fn build(self) -> Self {
self
}
}
#[derive(Debug, Clone, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WebDriverInterceptConfiguration {
pub enabled: bool,
}
impl WebDriverInterceptConfiguration {
pub fn new(enabled: bool) -> Self {
Self { enabled }
}
}