Skip to content

Commit

Permalink
[rust] Include webview2 in Edge module (#12904)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia authored Oct 9, 2023
1 parent 2a54d3c commit 5e64286
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
18 changes: 14 additions & 4 deletions rust/src/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ use crate::{
REG_VERSION_ARG, STABLE,
};

pub const EDGE_NAMES: &[&str] = &["edge", "msedge", "microsoftedge"];
pub const EDGE_NAMES: &[&str] = &[
"edge",
EDGE_WINDOWS_AND_LINUX_APP_NAME,
"microsoftedge",
WEBVIEW2_NAME,
];
pub const EDGEDRIVER_NAME: &str = "msedgedriver";
pub const WEBVIEW2_NAME: &str = "webview2";
const DRIVER_URL: &str = "https://msedgedriver.azureedge.net/";
const LATEST_STABLE: &str = "LATEST_STABLE";
const LATEST_RELEASE: &str = "LATEST_RELEASE";
Expand All @@ -61,13 +67,17 @@ pub struct EdgeManager {

impl EdgeManager {
pub fn new() -> Result<Box<Self>, Error> {
let browser_name = EDGE_NAMES[0];
Self::new_with_name(EDGE_NAMES[0].to_string())
}

pub fn new_with_name(browser_name: String) -> Result<Box<Self>, Error> {
let static_browser_name: &str = Box::leak(browser_name.into_boxed_str());
let driver_name = EDGEDRIVER_NAME;
let config = ManagerConfig::default(browser_name, driver_name);
let config = ManagerConfig::default(static_browser_name, driver_name);
let default_timeout = config.timeout.to_owned();
let default_proxy = &config.proxy;
Ok(Box::new(EdgeManager {
browser_name,
browser_name: static_browser_name,
driver_name,
http_client: create_http_client(default_timeout, default_proxy)?,
config,
Expand Down
11 changes: 8 additions & 3 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// under the License.

use crate::chrome::{ChromeManager, CHROMEDRIVER_NAME, CHROME_NAME};
use crate::edge::{EdgeManager, EDGEDRIVER_NAME, EDGE_NAMES};
use crate::edge::{EdgeManager, EDGEDRIVER_NAME, EDGE_NAMES, WEBVIEW2_NAME};
use crate::files::{
create_parent_path_if_not_exists, create_path_if_not_exists, default_cache_folder,
get_binary_extension, path_to_string,
Expand Down Expand Up @@ -499,6 +499,7 @@ pub trait SeleniumManager {
&& !self.is_iexplorer()
&& !self.is_grid()
&& !self.is_safari()
&& !self.is_webview2()
{
let browser_path = self.download_browser()?;
if browser_path.is_some() {
Expand Down Expand Up @@ -642,6 +643,10 @@ pub trait SeleniumManager {
self.get_browser_name().eq(EDGE_NAMES[0])
}

fn is_webview2(&self) -> bool {
self.get_browser_name().eq(WEBVIEW2_NAME)
}

fn is_browser_version_beta(&self) -> bool {
self.is_beta(self.get_browser_version())
}
Expand Down Expand Up @@ -1144,7 +1149,7 @@ pub trait SeleniumManager {
}

fn set_browser_path(&mut self, browser_path: String) {
if !browser_path.is_empty() {
if !browser_path.is_empty() && !self.is_webview2() {
self.get_config_mut().browser_path = browser_path;
}
}
Expand Down Expand Up @@ -1307,7 +1312,7 @@ pub fn get_manager_by_browser(browser_name: String) -> Result<Box<dyn SeleniumMa
} else if browser_name_lower_case.eq(FIREFOX_NAME) {
Ok(FirefoxManager::new()?)
} else if EDGE_NAMES.contains(&browser_name_lower_case.as_str()) {
Ok(EdgeManager::new()?)
Ok(EdgeManager::new_with_name(browser_name)?)
} else if IE_NAMES.contains(&browser_name_lower_case.as_str()) {
Ok(IExplorerManager::new()?)
} else if browser_name_lower_case.eq(SAFARI_NAME) {
Expand Down
20 changes: 19 additions & 1 deletion rust/tests/browser_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

use assert_cmd::Command;
use rstest::rstest;
use selenium_manager::logger::JsonOutput;
use std::env::consts::OS;

use crate::common::assert_output;
use crate::common::{assert_driver, assert_output};

mod common;

Expand Down Expand Up @@ -147,3 +148,20 @@ fn browser_path_test(#[case] os: String, #[case] browser: String, #[case] browse
assert!(!output.contains("WARN"));
}
}

#[test]
fn webview2_test() {
let mut cmd = Command::new(env!("CARGO_BIN_EXE_selenium-manager"));
cmd.args(["--browser", "webview2", "--output", "json"])
.assert()
.success()
.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());
}

0 comments on commit 5e64286

Please sign in to comment.