Skip to content

Commit

Permalink
[rust] Support for Chromium (#12511) (#12890)
Browse files Browse the repository at this point in the history
[rust] Detect chromium browser in path (#12511)

Co-authored-by: Titus Fortner <[email protected]>
  • Loading branch information
bonigarcia and titusfortner authored Oct 7, 2023
1 parent ecfa9c4 commit 73cfa22
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 15 deletions.
4 changes: 4 additions & 0 deletions rust/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions rust/src/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions rust/src/firefox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions rust/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions rust/src/iexplorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
29 changes: 14 additions & 15 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -392,10 +383,18 @@ pub trait SeleniumManager {
}

fn find_browser_in_path(&self) -> Option<PathBuf> {
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
}

Expand Down
4 changes: 4 additions & 0 deletions rust/src/safari.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions rust/src/safaritp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 73cfa22

Please sign in to comment.