Skip to content

Commit 0340853

Browse files
authored
Merge a9583c3 into dfacbe0
2 parents dfacbe0 + a9583c3 commit 0340853

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

rust/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ pub struct ManagerConfig {
5555
pub offline: bool,
5656
pub force_browser_download: bool,
5757
pub avoid_browser_download: bool,
58+
pub skip_driver_in_path: bool,
59+
pub skip_browser_in_path: bool,
5860
}
5961

6062
impl ManagerConfig {
@@ -111,6 +113,8 @@ impl ManagerConfig {
111113
offline: BooleanKey("offline", false).get_value(),
112114
force_browser_download: BooleanKey("force-browser-download", false).get_value(),
113115
avoid_browser_download: BooleanKey("avoid-browser-download", false).get_value(),
116+
skip_driver_in_path: BooleanKey("skip-driver-in-path", false).get_value(),
117+
skip_browser_in_path: BooleanKey("skip-browser-in-path", false).get_value(),
114118
}
115119
}
116120
}

rust/src/lib.rs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,16 @@ pub trait SeleniumManager {
382382
// Check browser in PATH
383383
let browser_in_path = self.find_browser_in_path();
384384
if let Some(path) = &browser_in_path {
385-
self.set_browser_path(path_to_string(path));
385+
if self.is_skip_browser_in_path() {
386+
self.get_logger().debug(format!(
387+
"Skipping {} in path: {}",
388+
self.get_browser_name(),
389+
path.display()
390+
));
391+
return None;
392+
} else {
393+
self.set_browser_path(path_to_string(path));
394+
}
386395
}
387396
browser_in_path
388397
}
@@ -775,8 +784,16 @@ pub trait SeleniumManager {
775784
self.get_major_browser_version()
776785
));
777786
}
778-
self.set_driver_version(version.to_string());
779-
return Ok(PathBuf::from(path));
787+
if self.is_skip_driver_in_path() {
788+
self.get_logger().debug(format!(
789+
"Skipping {} in path: {}",
790+
self.get_driver_name(),
791+
path
792+
));
793+
} else {
794+
self.set_driver_version(version.to_string());
795+
return Ok(PathBuf::from(path));
796+
}
780797
}
781798

782799
// If driver was not in the PATH, try to find it in the cache
@@ -1327,6 +1344,26 @@ pub trait SeleniumManager {
13271344
}
13281345
}
13291346

1347+
fn is_skip_driver_in_path(&self) -> bool {
1348+
self.get_config().skip_driver_in_path
1349+
}
1350+
1351+
fn set_skip_driver_in_path(&mut self, skip_driver_in_path: bool) {
1352+
if skip_driver_in_path {
1353+
self.get_config_mut().skip_driver_in_path = true;
1354+
}
1355+
}
1356+
1357+
fn is_skip_browser_in_path(&self) -> bool {
1358+
self.get_config().skip_browser_in_path
1359+
}
1360+
1361+
fn set_skip_browser_in_path(&mut self, skip_browser_in_path: bool) {
1362+
if skip_browser_in_path {
1363+
self.get_config_mut().skip_browser_in_path = true;
1364+
}
1365+
}
1366+
13301367
fn get_cache_path(&self) -> Result<Option<PathBuf>, Error> {
13311368
let path = Path::new(&self.get_config().cache_path);
13321369
match create_path_if_not_exists(path) {

rust/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ struct Cli {
131131
/// Avoid to download browser (even when browser-version is specified)
132132
#[clap(long)]
133133
avoid_browser_download: bool,
134+
135+
/// Not using drivers found in the PATH
136+
#[clap(long)]
137+
skip_driver_in_path: bool,
138+
139+
/// Not using browsers found in the PATH
140+
#[clap(long)]
141+
skip_browser_in_path: bool,
134142
}
135143

136144
fn main() {
@@ -196,6 +204,8 @@ fn main() {
196204
selenium_manager.set_avoid_browser_download(cli.avoid_browser_download);
197205
selenium_manager.set_cache_path(cache_path.clone());
198206
selenium_manager.set_offline(cli.offline);
207+
selenium_manager.set_skip_driver_in_path(cli.skip_driver_in_path);
208+
selenium_manager.set_skip_browser_in_path(cli.skip_browser_in_path);
199209

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

0 commit comments

Comments
 (0)