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

Method detect_browser_path

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

Source from the content-addressed store, hash-verified

430 }
431
432 fn detect_browser_path(&mut self) -> Option<PathBuf> {
433 // A driver's binary search is channel-agnostic and finds system browsers, so mirror it only
434 // for the default channel and when the user hasn't asked to skip browsers in the path.
435 if !self.is_browser_version_unstable()
436 && !self.is_skip_browser_in_path()
437 && let Some(browser_path) = self.detect_browser_in_known_locations()
438 {
439 let canon_browser_path = self.canonicalize_path(browser_path);
440 self.get_logger().debug(format!(
441 "{} detected at {}",
442 self.get_browser_name(),
443 canon_browser_path
444 ));
445 self.set_browser_path(canon_browser_path.clone());
446 return Some(Path::new(&canon_browser_path).to_path_buf());
447 }
448
449 let browser_version = self.get_browser_version();
450 let browser_path = self.get_browser_path_from_version(browser_version);
451
452 let mut full_browser_path = Path::new(browser_path).to_path_buf();
453 if WINDOWS.is(self.get_os()) {
454 let envs = vec![ENV_PROGRAM_FILES, ENV_PROGRAM_FILES_X86, ENV_LOCALAPPDATA];
455
456 for env in envs {
457 let mut env_value = env::var(env).unwrap_or_default();
458 if env.eq(ENV_PROGRAM_FILES) && env_value.contains(ENV_X86) {
459 // This special case is required to keep compliance between x32 and x64
460 // architectures (since the selenium-manager in Windows is compiled as x32 binary)
461 env_value = env_value.replace(ENV_X86, "");
462 }
463 let parent_path = Path::new(&env_value);
464 full_browser_path = parent_path.join(browser_path);
465 if full_browser_path.exists() {
466 break;
467 }
468 }
469 }
470
471 if full_browser_path.exists() {
472 let canon_browser_path = self.canonicalize_path(full_browser_path);
473 self.get_logger().debug(format!(
474 "{} detected at {}",
475 self.get_browser_name(),
476 canon_browser_path
477 ));
478 self.set_browser_path(canon_browser_path.clone());
479
480 Some(Path::new(&canon_browser_path).to_path_buf())
481 } else {
482 // Check browser in PATH
483 let browser_in_path = self.find_browser_in_path();
484 if let Some(path) = &browser_in_path {
485 if self.is_skip_browser_in_path() {
486 self.get_logger().debug(format!(
487 "Skipping {} in path: {}",
488 self.get_browser_name(),
489 path.display()

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 14

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

Tested by

no test coverage detected