Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Options:
--browser-version <BROWSER_VERSION>
Major browser version (e.g., 105, 106, etc. Also: beta, dev, canary -or nightly- is accepted)
--browser-path <BROWSER_PATH>
Browser path (absolute) for browser version detection (e.g., /usr/bin/google-chrome, "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome", "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe")
Browser path (absolute) for browser version detection (e.g., /usr/bin/google-chrome, "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome", "C:\Program Files\Google\Chrome\Application\chrome.exe")
--output <OUTPUT>
Output type: LOGGER (using INFO, WARN, etc.), JSON (custom JSON notation), or SHELL (Unix-like) [default: LOGGER]
--proxy <PROXY>
Expand Down
3 changes: 2 additions & 1 deletion rust/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ impl SeleniumManager for ChromeManager {

fn discover_browser_version(&self) -> Option<String> {
let mut commands;
let mut browser_path = self.get_browser_path();
let escaped_browser_path = self.get_escaped_browser_path();
let mut browser_path = escaped_browser_path.as_str();
if browser_path.is_empty() {
match self.detect_browser_path() {
Some(path) => {
Expand Down
3 changes: 2 additions & 1 deletion rust/src/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ impl SeleniumManager for EdgeManager {

fn discover_browser_version(&self) -> Option<String> {
let mut commands;
let mut browser_path = self.get_browser_path();
let escaped_browser_path = self.get_escaped_browser_path();
let mut browser_path = escaped_browser_path.as_str();
if browser_path.is_empty() {
match self.detect_browser_path() {
Some(path) => {
Expand Down
3 changes: 2 additions & 1 deletion rust/src/firefox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ impl SeleniumManager for FirefoxManager {

fn discover_browser_version(&self) -> Option<String> {
let mut commands;
let mut browser_path = self.get_browser_path();
let escaped_browser_path = self.get_escaped_browser_path();
let mut browser_path = escaped_browser_path.as_str();
if browser_path.is_empty() {
match self.detect_browser_path() {
Some(path) => {
Expand Down
16 changes: 16 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,22 @@ pub trait SeleniumManager {
self.get_config().browser_path.as_str()
}

fn get_escaped_browser_path(&self) -> String {
let mut browser_path = self.get_browser_path().to_string();
let path = Path::new(&browser_path);
if path.exists() && WINDOWS.is(self.get_os()) {
browser_path = Path::new(path)
.canonicalize()
.unwrap()
.to_str()
.unwrap()
.to_string()
.replace("\\\\?\\", "")
.replace("\\", "\\\\");
}
browser_path
}

fn set_browser_path(&mut self, browser_path: String) {
if !browser_path.is_empty() {
let mut config = self.get_config_mut();
Expand Down
2 changes: 1 addition & 1 deletion rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct Cli {

/// Browser path (absolute) for browser version detection (e.g., /usr/bin/google-chrome,
/// "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome",
/// "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe")
/// "C:\Program Files\Google\Chrome\Application\chrome.exe")
#[clap(long, value_parser)]
browser_path: Option<String>,

Expand Down
3 changes: 2 additions & 1 deletion rust/src/safari.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ impl SeleniumManager for SafariManager {
}

fn discover_browser_version(&self) -> Option<String> {
let mut browser_path = self.get_browser_path();
let escaped_browser_path = self.get_escaped_browser_path();
let mut browser_path = escaped_browser_path.as_str();
if browser_path.is_empty() {
match self.detect_browser_path() {
Some(path) => {
Expand Down
3 changes: 2 additions & 1 deletion rust/src/safaritp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ impl SeleniumManager for SafariTPManager {
}

fn discover_browser_version(&self) -> Option<String> {
let mut browser_path = self.get_browser_path();
let escaped_browser_path = self.get_escaped_browser_path();
let mut browser_path = escaped_browser_path.as_str();
if browser_path.is_empty() {
match self.detect_browser_path() {
Some(path) => {
Expand Down
19 changes: 17 additions & 2 deletions rust/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use assert_cmd::Command;
use rstest::rstest;
use std::env::consts::OS;
use std::str;

#[rstest]
Expand Down Expand Up @@ -132,15 +133,22 @@ fn beta_test(#[case] browser: String, #[case] driver_name: String) {

#[rstest]
#[case(
"windows",
"chrome",
r#"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"#
)]
#[case("chrome", "/usr/bin/google-chrome")]
#[case(
"windows",
"chrome",
r#"C:\Program Files\Google\Chrome\Application\chrome.exe"#
)]
#[case("linux", "chrome", "/usr/bin/google-chrome")]
#[case(
"macos",
"chrome",
r#"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"#
)]
fn path_test(#[case] browser: String, #[case] browser_path: String) {
fn path_test(#[case] os: String, #[case] browser: String, #[case] browser_path: String) {
println!(
"Path test browser={} -- browser_path={}",
browser, browser_path
Expand All @@ -151,4 +159,11 @@ fn path_test(#[case] browser: String, #[case] browser_path: String) {
.assert()
.success()
.code(0);

if OS.eq(&os) {
let stdout = &cmd.unwrap().stdout;
let output = str::from_utf8(stdout).unwrap();
println!("output {:?}", output);
assert!(!output.contains("WARN"));
}
}