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

Method detect_browser_path

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

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected