From 73cfa2284e42122a1c7d2ec3dbd9d1f966556c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boni=20Garc=C3=ADa?= Date: Sat, 7 Oct 2023 14:13:24 +0200 Subject: [PATCH] [rust] Support for Chromium (#12511) (#12890) [rust] Detect chromium browser in path (#12511) Co-authored-by: Titus Fortner --- rust/src/chrome.rs | 4 ++++ rust/src/edge.rs | 4 ++++ rust/src/firefox.rs | 4 ++++ rust/src/grid.rs | 4 ++++ rust/src/iexplorer.rs | 4 ++++ rust/src/lib.rs | 29 ++++++++++++++--------------- rust/src/safari.rs | 4 ++++ rust/src/safaritp.rs | 4 ++++ 8 files changed, 42 insertions(+), 15 deletions(-) diff --git a/rust/src/chrome.rs b/rust/src/chrome.rs index 80601856e41c5..b488aaadb34b9 100644 --- a/rust/src/chrome.rs +++ b/rust/src/chrome.rs @@ -211,6 +211,10 @@ impl SeleniumManager for ChromeManager { self.browser_name } + fn get_browser_names_in_path(&self) -> Vec<&str> { + vec![self.get_browser_name(), "chromium-browser", "chromium"] + } + fn get_http_client(&self) -> &Client { &self.http_client } diff --git a/rust/src/edge.rs b/rust/src/edge.rs index 26ac93d2da7f1..18e69bc41b207 100644 --- a/rust/src/edge.rs +++ b/rust/src/edge.rs @@ -69,6 +69,10 @@ impl SeleniumManager for EdgeManager { self.browser_name } + fn get_browser_names_in_path(&self) -> Vec<&str> { + vec![self.get_browser_name()] + } + fn get_http_client(&self) -> &Client { &self.http_client } diff --git a/rust/src/firefox.rs b/rust/src/firefox.rs index 276ecde8bb6f6..297f2248449d3 100644 --- a/rust/src/firefox.rs +++ b/rust/src/firefox.rs @@ -209,6 +209,10 @@ impl SeleniumManager for FirefoxManager { self.browser_name } + fn get_browser_names_in_path(&self) -> Vec<&str> { + vec![self.get_browser_name()] + } + fn get_http_client(&self) -> &Client { &self.http_client } diff --git a/rust/src/grid.rs b/rust/src/grid.rs index 295cc9ba3ae57..39d3437adeb36 100644 --- a/rust/src/grid.rs +++ b/rust/src/grid.rs @@ -74,6 +74,10 @@ impl SeleniumManager for GridManager { self.browser_name } + fn get_browser_names_in_path(&self) -> Vec<&str> { + vec![self.get_browser_name()] + } + fn get_http_client(&self) -> &Client { &self.http_client } diff --git a/rust/src/iexplorer.rs b/rust/src/iexplorer.rs index 829ac849b1e99..1a60216dfcb0a 100644 --- a/rust/src/iexplorer.rs +++ b/rust/src/iexplorer.rs @@ -79,6 +79,10 @@ impl SeleniumManager for IExplorerManager { self.browser_name } + fn get_browser_names_in_path(&self) -> Vec<&str> { + vec![self.get_browser_name()] + } + fn get_http_client(&self) -> &Client { &self.http_client } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 7684a43f477b4..28ddece6ae5a6 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -111,6 +111,8 @@ pub trait SeleniumManager { fn get_browser_name(&self) -> &str; + fn get_browser_names_in_path(&self) -> Vec<&str>; + fn get_http_client(&self) -> &Client; fn set_http_client(&mut self, http_client: Client); @@ -229,20 +231,9 @@ pub trait SeleniumManager { Some(Path::new(&canon_browser_path).to_path_buf()) } else { // Check browser in PATH - let browser_name = self.get_browser_name(); - self.get_logger() - .trace(format!("Checking {} in PATH", browser_name)); let browser_in_path = self.find_browser_in_path(); if let Some(path) = &browser_in_path { - let canon_browser_path = self.canonicalize_path(path.clone()); - self.get_logger().debug(format!( - "Found {} in PATH: {}", - browser_name, &canon_browser_path - )); - self.set_browser_path(canon_browser_path); - } else { - self.get_logger() - .debug(format!("{} not found in PATH", browser_name)); + self.set_browser_path(path_to_string(path)); } browser_in_path } @@ -392,10 +383,18 @@ pub trait SeleniumManager { } fn find_browser_in_path(&self) -> Option { - let browser_path = self.execute_which_in_shell(self.get_browser_name()); - if let Some(path) = browser_path { - return Some(Path::new(&path).to_path_buf()); + for browser_name in self.get_browser_names_in_path().iter() { + self.get_logger() + .trace(format!("Checking {} in PATH", browser_name)); + let browser_path = self.execute_which_in_shell(browser_name); + if let Some(path) = browser_path { + self.get_logger() + .debug(format!("Found {} in PATH: {}", browser_name, &path)); + return Some(Path::new(&path).to_path_buf()); + } } + self.get_logger() + .debug(format!("{} not found in PATH", self.get_browser_name())); None } diff --git a/rust/src/safari.rs b/rust/src/safari.rs index 13687d5ccd5bf..4489269e278e5 100644 --- a/rust/src/safari.rs +++ b/rust/src/safari.rs @@ -62,6 +62,10 @@ impl SeleniumManager for SafariManager { self.browser_name } + fn get_browser_names_in_path(&self) -> Vec<&str> { + vec![self.get_browser_name()] + } + fn get_http_client(&self) -> &Client { &self.http_client } diff --git a/rust/src/safaritp.rs b/rust/src/safaritp.rs index a3beed8a795c2..70d1720cc64e8 100644 --- a/rust/src/safaritp.rs +++ b/rust/src/safaritp.rs @@ -68,6 +68,10 @@ impl SeleniumManager for SafariTPManager { self.browser_name } + fn get_browser_names_in_path(&self) -> Vec<&str> { + vec![self.get_browser_name()] + } + fn get_http_client(&self) -> &Client { &self.http_client }