From 5e6428610e28bb9d5e1ef4288e58679856a4a49b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boni=20Garc=C3=ADa?= Date: Mon, 9 Oct 2023 22:18:38 +0200 Subject: [PATCH] [rust] Include webview2 in Edge module (#12904) --- rust/src/edge.rs | 18 ++++++++++++++---- rust/src/lib.rs | 11 ++++++++--- rust/tests/browser_tests.rs | 20 +++++++++++++++++++- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/rust/src/edge.rs b/rust/src/edge.rs index 97cf2ff979573..388e664cd3ceb 100644 --- a/rust/src/edge.rs +++ b/rust/src/edge.rs @@ -36,8 +36,14 @@ use crate::{ REG_VERSION_ARG, STABLE, }; -pub const EDGE_NAMES: &[&str] = &["edge", "msedge", "microsoftedge"]; +pub const EDGE_NAMES: &[&str] = &[ + "edge", + EDGE_WINDOWS_AND_LINUX_APP_NAME, + "microsoftedge", + WEBVIEW2_NAME, +]; pub const EDGEDRIVER_NAME: &str = "msedgedriver"; +pub const WEBVIEW2_NAME: &str = "webview2"; const DRIVER_URL: &str = "https://msedgedriver.azureedge.net/"; const LATEST_STABLE: &str = "LATEST_STABLE"; const LATEST_RELEASE: &str = "LATEST_RELEASE"; @@ -61,13 +67,17 @@ pub struct EdgeManager { impl EdgeManager { pub fn new() -> Result, Error> { - let browser_name = EDGE_NAMES[0]; + Self::new_with_name(EDGE_NAMES[0].to_string()) + } + + pub fn new_with_name(browser_name: String) -> Result, Error> { + let static_browser_name: &str = Box::leak(browser_name.into_boxed_str()); let driver_name = EDGEDRIVER_NAME; - let config = ManagerConfig::default(browser_name, driver_name); + let config = ManagerConfig::default(static_browser_name, driver_name); let default_timeout = config.timeout.to_owned(); let default_proxy = &config.proxy; Ok(Box::new(EdgeManager { - browser_name, + browser_name: static_browser_name, driver_name, http_client: create_http_client(default_timeout, default_proxy)?, config, diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 8ae44f6b8ef91..d059094e83d4c 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -16,7 +16,7 @@ // under the License. use crate::chrome::{ChromeManager, CHROMEDRIVER_NAME, CHROME_NAME}; -use crate::edge::{EdgeManager, EDGEDRIVER_NAME, EDGE_NAMES}; +use crate::edge::{EdgeManager, EDGEDRIVER_NAME, EDGE_NAMES, WEBVIEW2_NAME}; use crate::files::{ create_parent_path_if_not_exists, create_path_if_not_exists, default_cache_folder, get_binary_extension, path_to_string, @@ -499,6 +499,7 @@ pub trait SeleniumManager { && !self.is_iexplorer() && !self.is_grid() && !self.is_safari() + && !self.is_webview2() { let browser_path = self.download_browser()?; if browser_path.is_some() { @@ -642,6 +643,10 @@ pub trait SeleniumManager { self.get_browser_name().eq(EDGE_NAMES[0]) } + fn is_webview2(&self) -> bool { + self.get_browser_name().eq(WEBVIEW2_NAME) + } + fn is_browser_version_beta(&self) -> bool { self.is_beta(self.get_browser_version()) } @@ -1144,7 +1149,7 @@ pub trait SeleniumManager { } fn set_browser_path(&mut self, browser_path: String) { - if !browser_path.is_empty() { + if !browser_path.is_empty() && !self.is_webview2() { self.get_config_mut().browser_path = browser_path; } } @@ -1307,7 +1312,7 @@ pub fn get_manager_by_browser(browser_name: String) -> Result