diff --git a/rust/src/edge.rs b/rust/src/edge.rs index b2482bcecad84..c3464697e5ddf 100644 --- a/rust/src/edge.rs +++ b/rust/src/edge.rs @@ -25,7 +25,7 @@ use crate::metadata::{ }; use crate::{ create_http_client, get_binary_extension, path_to_string, Logger, SeleniumManager, BETA, - DASH_DASH_VERSION, DEV, ENV_PROGRAM_FILES_X86, NIGHTLY, OFFLINE_REQUEST_ERR_MSG, + DASH_DASH_VERSION, DEV, ENV_PROGRAM_FILES_X86, NIGHTLY, OFFLINE_REQUEST_ERR_MSG, REG_PV_ARG, REG_VERSION_ARG, STABLE, }; use anyhow::Error; @@ -104,54 +104,79 @@ impl SeleniumManager for EdgeManager { } fn get_browser_path_map(&self) -> HashMap { - HashMap::from([ - ( + if self.is_webview2() { + HashMap::from([( BrowserPath::new(WINDOWS, STABLE), - r#"Microsoft\Edge\Application\msedge.exe"#, - ), - ( - BrowserPath::new(WINDOWS, BETA), - r#"Microsoft\Edge Beta\Application\msedge.exe"#, - ), - ( - BrowserPath::new(WINDOWS, DEV), - r#"Microsoft\Edge Dev\Application\msedge.exe"#, - ), - ( - BrowserPath::new(WINDOWS, NIGHTLY), - r#"Microsoft\Edge SxS\Application\msedge.exe"#, - ), - ( - BrowserPath::new(MACOS, STABLE), - r#"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"#, - ), - ( - BrowserPath::new(MACOS, BETA), - r#"/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta"#, - ), - ( - BrowserPath::new(MACOS, DEV), - r#"/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev"#, - ), - ( - BrowserPath::new(MACOS, NIGHTLY), - r#"/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary"#, - ), - (BrowserPath::new(LINUX, STABLE), "/usr/bin/microsoft-edge"), - ( - BrowserPath::new(LINUX, BETA), - "/usr/bin/microsoft-edge-beta", - ), - (BrowserPath::new(LINUX, DEV), "/usr/bin/microsoft-edge-dev"), - ]) + r#"Microsoft\EdgeWebView\Application"#, + )]) + } else { + HashMap::from([ + ( + BrowserPath::new(WINDOWS, STABLE), + r#"Microsoft\Edge\Application\msedge.exe"#, + ), + ( + BrowserPath::new(WINDOWS, BETA), + r#"Microsoft\Edge Beta\Application\msedge.exe"#, + ), + ( + BrowserPath::new(WINDOWS, DEV), + r#"Microsoft\Edge Dev\Application\msedge.exe"#, + ), + ( + BrowserPath::new(WINDOWS, NIGHTLY), + r#"Microsoft\Edge SxS\Application\msedge.exe"#, + ), + ( + BrowserPath::new(MACOS, STABLE), + r#"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"#, + ), + ( + BrowserPath::new(MACOS, BETA), + r#"/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta"#, + ), + ( + BrowserPath::new(MACOS, DEV), + r#"/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev"#, + ), + ( + BrowserPath::new(MACOS, NIGHTLY), + r#"/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary"#, + ), + (BrowserPath::new(LINUX, STABLE), "/usr/bin/microsoft-edge"), + ( + BrowserPath::new(LINUX, BETA), + "/usr/bin/microsoft-edge-beta", + ), + (BrowserPath::new(LINUX, DEV), "/usr/bin/microsoft-edge-dev"), + ]) + } } fn discover_browser_version(&mut self) -> Result, Error> { - self.general_discover_browser_version( - r#"HKCU\Software\Microsoft\Edge\BLBeacon"#, - REG_VERSION_ARG, - DASH_DASH_VERSION, - ) + let (reg_key, reg_version_arg, cmd_version_arg) = if self.is_webview2() { + let arch = self.get_arch(); + if X32.is(arch) { + ( + r#"HKLM\SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"#, + REG_PV_ARG, + "", + ) + } else { + ( + r#"HKLM\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"#, + REG_PV_ARG, + "", + ) + } + } else { + ( + r#"HKCU\Software\Microsoft\Edge\BLBeacon"#, + REG_VERSION_ARG, + DASH_DASH_VERSION, + ) + }; + self.general_discover_browser_version(reg_key, reg_version_arg, cmd_version_arg) } fn get_driver_name(&self) -> &str { diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 8ab7ccaa2dda8..6d4388a5df54c 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -73,6 +73,7 @@ pub const WMIC_COMMAND: &str = r#"wmic datafile where name='{}' get Version /val pub const WMIC_COMMAND_OS: &str = r#"wmic os get osarchitecture"#; pub const REG_VERSION_ARG: &str = "version"; pub const REG_CURRENT_VERSION_ARG: &str = "CurrentVersion"; +pub const REG_PV_ARG: &str = "pv"; pub const PLIST_COMMAND: &str = r#"/usr/libexec/PlistBuddy -c "print :CFBundleShortVersionString" {}/Contents/Info.plist"#; pub const PKGUTIL_COMMAND: &str = "pkgutil --expand-full {} {}"; @@ -483,6 +484,15 @@ pub trait SeleniumManager { } else { self.set_browser_version(discovered_version); } + if self.is_webview2() { + let browser_path = format!( + r#"{}\{}\msedge{}"#, + self.get_browser_path(), + &self.get_browser_version(), + get_binary_extension(self.get_os()) + ); + self.set_browser_path(browser_path); + } } None => { self.get_logger().debug(format!( @@ -984,7 +994,7 @@ pub trait SeleniumManager { let mut commands = Vec::new(); if WINDOWS.is(self.get_os()) { - if !escaped_browser_path.is_empty() { + if !escaped_browser_path.is_empty() && !self.is_webview2() { let wmic_command = Command::new_single(format_one_arg(WMIC_COMMAND, &escaped_browser_path)); commands.push(wmic_command); @@ -1159,7 +1169,7 @@ pub trait SeleniumManager { } fn set_browser_path(&mut self, browser_path: String) { - if !browser_path.is_empty() && !self.is_webview2() { + if !browser_path.is_empty() { self.get_config_mut().browser_path = browser_path; } } diff --git a/rust/tests/browser_tests.rs b/rust/tests/browser_tests.rs index 80267998af10c..9496965bc03eb 100644 --- a/rust/tests/browser_tests.rs +++ b/rust/tests/browser_tests.rs @@ -18,7 +18,6 @@ use crate::common::{assert_driver, assert_output}; use assert_cmd::Command; use rstest::rstest; -use selenium_manager::logger::JsonOutput; use std::env::consts::OS; mod common; @@ -157,10 +156,4 @@ fn webview2_test() { .code(0); assert_driver(&mut cmd); - - let stdout = &cmd.unwrap().stdout; - let output = std::str::from_utf8(stdout).unwrap(); - let json: JsonOutput = serde_json::from_str(output).unwrap(); - let browser_path = json.result.browser_path; - assert!(browser_path.is_empty()); }