MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / detect_browser_path

Method detect_browser_path

rust/src/lib.rs:424–474  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

422 }
423
424 fn detect_browser_path(&mut self) -> Option<PathBuf> {
425 let browser_version = self.get_browser_version();
426 let browser_path = self.get_browser_path_from_version(browser_version);
427
428 let mut full_browser_path = Path::new(browser_path).to_path_buf();
429 if WINDOWS.is(self.get_os()) {
430 let envs = vec![ENV_PROGRAM_FILES, ENV_PROGRAM_FILES_X86, ENV_LOCALAPPDATA];
431
432 for env in envs {
433 let mut env_value = env::var(env).unwrap_or_default();
434 if env.eq(ENV_PROGRAM_FILES) && env_value.contains(ENV_X86) {
435 // This special case is required to keep compliance between x32 and x64
436 // architectures (since the selenium-manager in Windows is compiled as x32 binary)
437 env_value = env_value.replace(ENV_X86, "");
438 }
439 let parent_path = Path::new(&env_value);
440 full_browser_path = parent_path.join(browser_path);
441 if full_browser_path.exists() {
442 break;
443 }
444 }
445 }
446
447 if full_browser_path.exists() {
448 let canon_browser_path = self.canonicalize_path(full_browser_path);
449 self.get_logger().debug(format!(
450 "{} detected at {}",
451 self.get_browser_name(),
452 canon_browser_path
453 ));
454 self.set_browser_path(canon_browser_path.clone());
455
456 Some(Path::new(&canon_browser_path).to_path_buf())
457 } else {
458 // Check browser in PATH
459 let browser_in_path = self.find_browser_in_path();
460 if let Some(path) = &browser_in_path {
461 if self.is_skip_browser_in_path() {
462 self.get_logger().debug(format!(
463 "Skipping {} in path: {}",
464 self.get_browser_name(),
465 path.display()
466 ));
467 return None;
468 } else {
469 self.set_browser_path(path_to_string(path));
470 }
471 }
472 browser_in_path
473 }
474 }
475
476 fn detect_browser_version(&self, commands: Vec<Command>) -> Option<String> {
477 let browser_name = &self.get_browser_name();

Callers 2

Implementers 8

edge.rsrust/src/edge.rs
iexplorer.rsrust/src/iexplorer.rs
safaritp.rsrust/src/safaritp.rs
electron.rsrust/src/electron.rs
chrome.rsrust/src/chrome.rs
firefox.rsrust/src/firefox.rs
grid.rsrust/src/grid.rs
safari.rsrust/src/safari.rs

Calls 12

path_to_stringFunction · 0.85
get_browser_versionMethod · 0.80
get_osMethod · 0.80
canonicalize_pathMethod · 0.80
set_browser_pathMethod · 0.80
find_browser_in_pathMethod · 0.80
isMethod · 0.65
existsMethod · 0.45
debugMethod · 0.45
get_loggerMethod · 0.45

Tested by

no test coverage detected