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
4 changes: 4 additions & 0 deletions rust/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub struct ManagerConfig {
pub language_binding: String,
pub selenium_version: String,
pub avoid_stats: bool,
pub skip_driver_in_path: bool,
pub skip_browser_in_path: bool,
}

impl ManagerConfig {
Expand Down Expand Up @@ -117,6 +119,8 @@ impl ManagerConfig {
language_binding: StringKey(vec!["language-binding"], "").get_value(),
selenium_version: StringKey(vec!["selenium-version"], "").get_value(),
avoid_stats: BooleanKey("avoid-stats", false).get_value(),
skip_driver_in_path: BooleanKey("skip-driver-in-path", false).get_value(),
skip_browser_in_path: BooleanKey("skip-browser-in-path", false).get_value(),
}
}
}
Expand Down
82 changes: 60 additions & 22 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,16 @@ pub trait SeleniumManager {
// Check browser in PATH
let browser_in_path = self.find_browser_in_path();
if let Some(path) = &browser_in_path {
self.set_browser_path(path_to_string(path));
if self.is_skip_browser_in_path() {
self.get_logger().debug(format!(
"Skipping {} in path: {}",
self.get_browser_name(),
path.display()
));
return None;
} else {
self.set_browser_path(path_to_string(path));
}
}
browser_in_path
}
Expand Down Expand Up @@ -756,32 +765,41 @@ pub trait SeleniumManager {

// Use driver in PATH when the user has not specified any browser version
if use_driver_in_path {
let version = driver_in_path_version.unwrap();
let path = driver_in_path.unwrap();
let major_version = self.get_major_version(&version)?;

// Display warning if the discovered driver version is not the same as the driver in PATH
if !self.get_driver_version().is_empty()
&& (self.is_firefox() && !version.eq(self.get_driver_version()))
|| (!self.is_firefox() && !major_version.eq(&self.get_major_browser_version()))
{
self.get_logger().warn(format!(
"The {} version ({}) detected in PATH at {} might not be compatible with \
the detected {} version ({}); currently, {} {} is recommended for {} {}.*, \
so it is advised to delete the driver in PATH and retry",
self.get_driver_name(),
&version,
path,
self.get_browser_name(),
self.get_browser_version(),
if self.is_skip_driver_in_path() {
self.get_logger().debug(format!(
"Skipping {} in path: {}",
self.get_driver_name(),
self.get_driver_version(),
self.get_browser_name(),
self.get_major_browser_version()
path
));
} else {
let version = driver_in_path_version.unwrap();
let major_version = self.get_major_version(&version)?;

// Display warning if the discovered driver version is not the same as the driver in PATH
if !self.get_driver_version().is_empty()
&& (self.is_firefox() && !version.eq(self.get_driver_version()))
|| (!self.is_firefox() && !major_version.eq(&self.get_major_browser_version()))
{
self.get_logger().warn(format!(
"The {} version ({}) detected in PATH at {} might not be compatible with \
the detected {} version ({}); currently, {} {} is recommended for {} {}.*, \
so it is advised to delete the driver in PATH and retry",
self.get_driver_name(),
&version,
path,
self.get_browser_name(),
self.get_browser_version(),
self.get_driver_name(),
self.get_driver_version(),
self.get_browser_name(),
self.get_major_browser_version()
));
}
self.set_driver_version(version.to_string());
return Ok(PathBuf::from(path));
}
self.set_driver_version(version.to_string());
return Ok(PathBuf::from(path));
}

// If driver was not in the PATH, try to find it in the cache
Expand Down Expand Up @@ -1413,6 +1431,26 @@ pub trait SeleniumManager {
}
}

fn is_skip_driver_in_path(&self) -> bool {
self.get_config().skip_driver_in_path
}

fn set_skip_driver_in_path(&mut self, skip_driver_in_path: bool) {
if skip_driver_in_path {
self.get_config_mut().skip_driver_in_path = true;
}
}

fn is_skip_browser_in_path(&self) -> bool {
self.get_config().skip_browser_in_path
}

fn set_skip_browser_in_path(&mut self, skip_browser_in_path: bool) {
if skip_browser_in_path {
self.get_config_mut().skip_browser_in_path = true;
}
}

fn get_cache_path(&self) -> Result<Option<PathBuf>, Error> {
let path = Path::new(&self.get_config().cache_path);
match create_path_if_not_exists(path) {
Expand Down
10 changes: 10 additions & 0 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ struct Cli {
/// Avoid sends usage statistics to plausible.io
#[clap(long)]
avoid_stats: bool,

/// Not using drivers found in the PATH
#[clap(long)]
skip_driver_in_path: bool,

/// Not using browsers found in the PATH
#[clap(long)]
skip_browser_in_path: bool,
}

fn main() {
Expand Down Expand Up @@ -218,6 +226,8 @@ fn main() {
let selenium_version = sm_version.strip_prefix(SM_BETA_LABEL).unwrap_or(sm_version);
selenium_manager.set_selenium_version(selenium_version.to_string());
selenium_manager.set_avoid_stats(cli.avoid_stats);
selenium_manager.set_skip_driver_in_path(cli.skip_driver_in_path);
selenium_manager.set_skip_browser_in_path(cli.skip_browser_in_path);

if cli.clear_cache || BooleanKey("clear-cache", false).get_value() {
clear_cache(selenium_manager.get_logger(), &cache_path);
Expand Down