Skip to content

Commit

Permalink
[rust] Support for beta/dev/canary browser version detection with Sel…
Browse files Browse the repository at this point in the history
…enium Manager (#11239) (#11334)

[rust] Support for beta/dev/canary browser version detection with Selenium Manager
  • Loading branch information
bonigarcia committed Dec 7, 2022
1 parent 104b7b9 commit aa8d6cf
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 86 deletions.
6 changes: 3 additions & 3 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Automated driver management for Selenium
Usage: selenium-manager [OPTIONS]
Options:
-b, --browser <BROWSER>
Browser name (chrome, firefox, or edge) [default: ]
Browser name (chrome, firefox, edge, or iexplorer) [default: ]
-d, --driver <DRIVER>
Driver name (chromedriver, geckodriver, or msedgedriver) [default: ]
Driver name (chromedriver, geckodriver, msedgedriver, or IEDriverServer) [default: ]
-v, --driver-version <DRIVER_VERSION>
Driver version (e.g., 106.0.5249.61, 0.31.0, etc.) [default: ]
-B, --browser-version <BROWSER_VERSION>
Major browser version (e.g., 105, 106, etc.) [default: ]
Major browser version (e.g., 105, 106, etc. Also: beta, dev, canary -or nightly- is accepted) [default: ]
-D, --debug
Display DEBUG messages
-T, --trace
Expand Down
95 changes: 73 additions & 22 deletions rust/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@
// specific language governing permissions and limitations
// under the License.

use std::collections::HashMap;
use std::error::Error;
use std::path::PathBuf;

use crate::downloads::read_content_from_link;
use crate::files::compose_driver_path_in_cache;
use crate::is_unstable;
use crate::manager::ARCH::ARM64;
use crate::manager::OS::{MACOS, WINDOWS};
use crate::manager::{detect_browser_version, get_major_version, BrowserManager};
use crate::manager::OS::{LINUX, MACOS, WINDOWS};
use crate::manager::{
detect_browser_version, format_one_arg, format_two_args, get_major_version, BrowserManager,
BrowserPath, BETA, DASH_DASH_VERSION, DEV, ENV_LOCALAPPDATA, ENV_PROGRAM_FILES,
ENV_PROGRAM_FILES_X86, NIGHTLY, REG_QUERY, STABLE, WMIC_COMMAND,
};
use crate::metadata::{
create_driver_metadata, get_driver_version_from_metadata, get_metadata, write_metadata,
};
Expand Down Expand Up @@ -51,28 +57,73 @@ impl BrowserManager for ChromeManager {
self.browser_name
}

fn get_browser_version(&self, os: &str) -> Option<String> {
let (shell, flag, args) = if WINDOWS.is(os) {
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str> {
HashMap::from([
(
"cmd",
"/C",
vec![
r#"wmic datafile where name='%PROGRAMFILES:\=\\%\\Google\\Chrome\\Application\\chrome.exe' get Version /value"#,
r#"wmic datafile where name='%PROGRAMFILES(X86):\=\\%\\Google\\Chrome\\Application\\chrome.exe' get Version /value"#,
r#"wmic datafile where name='%LOCALAPPDATA:\=\\%\\Google\\Chrome\\Application\\chrome.exe' get Version /value"#,
r#"REG QUERY HKCU\Software\Google\Chrome\BLBeacon /v version"#,
],
)
} else if MACOS.is(os) {
BrowserPath::new(WINDOWS, STABLE),
r#"\\Google\\Chrome\\Application\\chrome.exe"#,
),
(
"sh",
"-c",
vec![r#"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version"#],
)
} else {
("sh", "-c", vec!["google-chrome --version"])
};
detect_browser_version(self.browser_name, shell, flag, args)
BrowserPath::new(WINDOWS, BETA),
r#"\\Google\\Chrome Beta\\Application\\chrome.exe"#,
),
(
BrowserPath::new(WINDOWS, DEV),
r#"\\Google\\Chrome Dev\\Application\\chrome.exe"#,
),
(
BrowserPath::new(WINDOWS, NIGHTLY),
r#"\\Google\\Chrome SxS\\Application\\chrome.exe"#,
),
(
BrowserPath::new(MACOS, STABLE),
r#"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"#,
),
(
BrowserPath::new(MACOS, BETA),
r#"/Applications/Google\ Chrome\ Beta.app/Contents/MacOS/Google\ Chrome\ Beta"#,
),
(
BrowserPath::new(MACOS, DEV),
r#"/Applications/Google\ Chrome\ Dev.app/Contents/MacOS/Google\ Chrome\ Dev"#,
),
(
BrowserPath::new(MACOS, NIGHTLY),
r#"/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary"#,
),
(BrowserPath::new(LINUX, STABLE), "google-chrome"),
(BrowserPath::new(LINUX, BETA), "google-chrome-beta"),
(BrowserPath::new(LINUX, DEV), "google-chrome-unstable"),
])
}

fn get_browser_version(&self, os: &str, browser_version: &str) -> Option<String> {
match self.get_browser_path(os, browser_version) {
Some(browser_path) => {
let (shell, flag, args) = if WINDOWS.is(os) {
let mut commands = vec![
format_two_args(WMIC_COMMAND, ENV_PROGRAM_FILES, browser_path),
format_two_args(WMIC_COMMAND, ENV_PROGRAM_FILES_X86, browser_path),
format_two_args(WMIC_COMMAND, ENV_LOCALAPPDATA, browser_path),
];
if !is_unstable(browser_version) {
commands.push(format_one_arg(
REG_QUERY,
r#"HKCU\Software\Google\Chrome\BLBeacon"#,
));
}
("cmd", "/C", commands)
} else {
(
"sh",
"-c",
vec![format_one_arg(DASH_DASH_VERSION, browser_path)],
)
};
detect_browser_version(self.browser_name, shell, flag, args)
}
_ => None,
}
}

fn get_driver_name(&self) -> &str {
Expand Down
95 changes: 72 additions & 23 deletions rust/src/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@
// specific language governing permissions and limitations
// under the License.

use std::collections::HashMap;
use std::error::Error;
use std::path::PathBuf;

use crate::downloads::read_content_from_link;
use crate::files::compose_driver_path_in_cache;
use crate::is_unstable;
use crate::manager::ARCH::{ARM64, X32};
use crate::manager::OS::{MACOS, WINDOWS};
use crate::manager::{detect_browser_version, BrowserManager};
use crate::manager::OS::{LINUX, MACOS, WINDOWS};
use crate::manager::{
detect_browser_version, format_one_arg, format_two_args, BrowserManager, BrowserPath, BETA,
DASH_DASH_VERSION, DEV, ENV_PROGRAM_FILES, ENV_PROGRAM_FILES_X86, NIGHTLY, REG_QUERY, STABLE,
WMIC_COMMAND,
};
use crate::metadata::{
create_driver_metadata, get_driver_version_from_metadata, get_metadata, write_metadata,
};
Expand Down Expand Up @@ -52,29 +58,72 @@ impl BrowserManager for EdgeManager {
self.browser_name
}

fn get_browser_version(&self, os: &str) -> Option<String> {
let (shell, flag, args) = if WINDOWS.is(os) {
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str> {
HashMap::from([
(
"cmd",
"/C",
vec![
r#"wmic datafile where name='%PROGRAMFILES(X86):\=\\%\\Microsoft\\Edge\\Application\\msedge.exe' get Version /value"#,
r#"wmic datafile where name='%PROGRAMFILES:\=\\%\\Microsoft\\Edge\\Application\\msedge.exe' get Version /value"#,
r#"REG QUERY HKCU\Software\Microsoft\Edge\BLBeacon /v version"#,
],
)
} else if MACOS.is(os) {
BrowserPath::new(WINDOWS, STABLE),
r#"\\Microsoft\\Edge\\Application\\msedge.exe"#,
),
(
"sh",
"-c",
vec![
r#"/Applications/Microsoft\ Edge.app/Contents/MacOS/Microsoft\ Edge -version"#,
],
)
} else {
("sh", "-c", vec!["microsoft-edge --version"])
};
detect_browser_version(self.browser_name, shell, flag, args)
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), "microsoft-edge"),
(BrowserPath::new(LINUX, BETA), "microsoft-edge-beta"),
(BrowserPath::new(LINUX, DEV), "microsoft-edge-dev"),
])
}

fn get_browser_version(&self, os: &str, browser_version: &str) -> Option<String> {
match self.get_browser_path(os, browser_version) {
Some(browser_path) => {
let (shell, flag, args) = if WINDOWS.is(os) {
let mut commands = vec![
format_two_args(WMIC_COMMAND, ENV_PROGRAM_FILES_X86, browser_path),
format_two_args(WMIC_COMMAND, ENV_PROGRAM_FILES, browser_path),
];
if !is_unstable(browser_version) {
commands.push(format_one_arg(
REG_QUERY,
r#"REG QUERY HKCU\Software\Microsoft\Edge\BLBeacon"#,
));
}
("cmd", "/C", commands)
} else {
(
"sh",
"-c",
vec![format_one_arg(DASH_DASH_VERSION, browser_path)],
)
};
detect_browser_version(self.browser_name, shell, flag, args)
}
_ => None,
}
}

fn get_driver_name(&self) -> &str {
Expand Down
85 changes: 65 additions & 20 deletions rust/src/firefox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
// specific language governing permissions and limitations
// under the License.

use std::collections::HashMap;
use std::error::Error;
use std::path::PathBuf;

use crate::downloads::read_redirect_from_link;
use crate::files::compose_driver_path_in_cache;
use crate::manager::ARCH::{ARM64, X32};
use crate::manager::OS::{MACOS, WINDOWS};
use crate::manager::{detect_browser_version, get_minor_version, BrowserManager};
use crate::manager::OS::{LINUX, MACOS, WINDOWS};
use crate::manager::{
detect_browser_version, format_one_arg, format_two_args, get_minor_version, BrowserManager,
BrowserPath, BETA, DASH_VERSION, DEV, ENV_PROGRAM_FILES, ENV_PROGRAM_FILES_X86, NIGHTLY,
STABLE, WMIC_COMMAND,
};
use crate::metadata::{
create_driver_metadata, get_driver_version_from_metadata, get_metadata, write_metadata,
};
Expand Down Expand Up @@ -51,26 +56,66 @@ impl BrowserManager for FirefoxManager {
self.browser_name
}

fn get_browser_version(&self, os: &str) -> Option<String> {
let (shell, flag, args) = if WINDOWS.is(os) {
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str> {
HashMap::from([
(
"cmd",
"/C",
vec![
r#"cmd.exe /C wmic datafile where name='%PROGRAMFILES:\=\\%\\Mozilla Firefox\\firefox.exe' get Version /value"#,
r#"cmd.exe /C wmic datafile where name='%PROGRAMFILES(X86):\=\\%\\Mozilla Firefox\\firefox.exe' get Version /value' get Version /value"#,
],
)
} else if MACOS.is(os) {
BrowserPath::new(WINDOWS, STABLE),
r#"\\Mozilla Firefox\\firefox.exe"#,
),
(
"sh",
"-c",
vec![r#"/Applications/Firefox.app/Contents/MacOS/firefox -v"#],
)
} else {
("sh", "-c", vec!["firefox -v"])
};
detect_browser_version(self.browser_name, shell, flag, args)
BrowserPath::new(WINDOWS, BETA),
r#"\\Mozilla Firefox\\firefox.exe"#,
),
(
BrowserPath::new(WINDOWS, DEV),
r#"\\Firefox Developer Edition\\firefox.exe"#,
),
(
BrowserPath::new(WINDOWS, NIGHTLY),
r#"\\Firefox Nightly\\firefox.exe"#,
),
(
BrowserPath::new(MACOS, STABLE),
r#"/Applications/Firefox.app/Contents/MacOS/firefox"#,
),
(
BrowserPath::new(MACOS, BETA),
r#"/Applications/Firefox.app/Contents/MacOS/firefox"#,
),
(
BrowserPath::new(MACOS, DEV),
r#"/Applications/Firefox\ Developer\ Edition.app/Contents/MacOS/firefox"#,
),
(
BrowserPath::new(MACOS, NIGHTLY),
r#"/Applications/Firefox\ Nightly.app/Contents/MacOS/firefox"#,
),
(BrowserPath::new(LINUX, STABLE), "firefox"),
(BrowserPath::new(LINUX, BETA), "firefox"),
(BrowserPath::new(LINUX, DEV), "firefox"),
(BrowserPath::new(LINUX, NIGHTLY), "firefox-trunk"),
])
}

fn get_browser_version(&self, os: &str, browser_version: &str) -> Option<String> {
match self.get_browser_path(os, browser_version) {
Some(browser_path) => {
let (shell, flag, args) = if WINDOWS.is(os) {
(
"cmd",
"/C",
vec![
format_two_args(WMIC_COMMAND, ENV_PROGRAM_FILES, browser_path),
format_two_args(WMIC_COMMAND, ENV_PROGRAM_FILES_X86, browser_path),
],
)
} else {
("sh", "-c", vec![format_one_arg(DASH_VERSION, browser_path)])
};
detect_browser_version(self.browser_name, shell, flag, args)
}
_ => None,
}
}

fn get_driver_name(&self) -> &str {
Expand Down
9 changes: 7 additions & 2 deletions rust/src/iexplorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
// specific language governing permissions and limitations
// under the License.

use std::collections::HashMap;
use std::error::Error;
use std::path::PathBuf;

use crate::downloads::read_redirect_from_link;
use crate::files::compose_driver_path_in_cache;

use crate::manager::{get_minor_version, BrowserManager};
use crate::manager::{get_minor_version, BrowserManager, BrowserPath};

use crate::metadata::{
create_driver_metadata, get_driver_version_from_metadata, get_metadata, write_metadata,
Expand Down Expand Up @@ -51,7 +52,11 @@ impl BrowserManager for IExplorerManager {
self.browser_name
}

fn get_browser_version(&self, _os: &str) -> Option<String> {
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str> {
HashMap::new()
}

fn get_browser_version(&self, _os: &str, _browser_version: &str) -> Option<String> {
None
}

Expand Down
Loading

0 comments on commit aa8d6cf

Please sign in to comment.