Skip to content

Commit

Permalink
[rust] Add --browser-version and --driver-version to selenium-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Oct 10, 2022
1 parent 3394c48 commit 8a2e87e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ third_party/py/googlestorage/client_secrets.json
venv
venv3
py/.idea
rust/target
rust/.idea

# Bazel stuff
bazel-bin
Expand Down
12 changes: 6 additions & 6 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "1.0.0-M1"
edition = "2021"

[dependencies]
clap = { version = "4.0.9", features = ["derive"] }
clap = { version = "4.0.11", features = ["derive"] }
log = "0.4.0"
env_logger = "0.9.1"
regex = "1.6.0"
Expand All @@ -14,7 +14,7 @@ reqwest = "0.11.12"
zip = "0.6.2"
directories = "4.0.1"
serde = { version = "1.0.145", features = ["derive"] }
serde_json = "1.0.85"
serde_json = "1.0.86"
flate2 = "1.0.24"
tar = "0.4.38"
infer = "0.9.0"
Expand Down
24 changes: 17 additions & 7 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,24 @@ $ cargo run -- --help
selenium-manager 1.0.0-M1
Automated driver management for Selenium
Usage: selenium-manager [OPTIONS] --browser <BROWSER>
Usage: selenium-manager.exe [OPTIONS] --browser <BROWSER>
Options:
-b, --browser <BROWSER> Browser type (e.g., chrome, firefox, edge)
-v, --version <VERSION> Major browser version (e.g., 105, 106, etc.) [default: ]
-d, --debug Display DEBUG messages
-t, --trace Display TRACE messages
-c, --clear-cache Clear driver cache
-h, --help Print help information
-b, --browser <BROWSER>
Browser type (e.g., chrome, firefox, edge)
-D, --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: ]
-d, --debug
Display DEBUG messages
-t, --trace
Display TRACE messages
-c, --clear-cache
Clear driver cache
-h, --help
Print help information
-V, --version
Print version information
```

For instance, the command required to manage chromedriver is the following:
Expand Down
35 changes: 21 additions & 14 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod metadata;

/// Automated driver management for Selenium
#[derive(Parser, Debug)]
#[clap(version, about, long_about = None, disable_version_flag = true, help_template = "\
#[clap(version, about, long_about = None, help_template = "\
{name} {version}
{about-with-newline}
{usage-heading} {usage}
Expand All @@ -34,9 +34,13 @@ struct Cli {
#[clap(short, long, value_parser)]
browser: String,

/// Driver version (e.g., 106.0.5249.61, 0.31.0, etc.)
#[clap(short = 'D', long, value_parser, default_value = "")]
driver_version: String,

/// Major browser version (e.g., 105, 106, etc.)
#[clap(short, long, value_parser, default_value = "")]
version: String,
#[clap(short = 'B', long, value_parser, default_value = "")]
browser_version: String,

/// Display DEBUG messages
#[clap(short, long)]
Expand Down Expand Up @@ -71,20 +75,23 @@ fn main() -> Result<(), Box<dyn Error>> {
clear_cache();
}

let mut browser_version = cli.version;
if browser_version.is_empty() {
let mut driver_version = cli.driver_version;
if driver_version.is_empty() {
let mut browser_version = cli.browser_version;
if browser_version.is_empty() {
match browser_manager.get_browser_version(os) {
Some(version) => {
browser_version = version;
log::debug!("Detected browser: {} {}", browser_name, browser_version);
}
None => {
log::warn!("The version of {} cannot be detected. Trying with latest driver version", browser_name);
}
Some(version) => {
browser_version = version;
log::debug!("Detected browser: {} {}", browser_name, browser_version);
}
None => {
log::warn!("The version of {} cannot be detected. Trying with latest driver version", browser_name);
}
}
}
driver_version = browser_manager.get_driver_version(&browser_version, os)?;
log::debug!("Required driver: {} {}", browser_manager.get_driver_name(), driver_version);
}
let driver_version = browser_manager.get_driver_version(&browser_version, os)?;
log::debug!("Required driver: {} {}", browser_manager.get_driver_name(), driver_version);

let driver_path = browser_manager.get_driver_path_in_cache(&driver_version, os, arch);
if driver_path.exists() {
Expand Down
2 changes: 1 addition & 1 deletion rust/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn cli_test(#[case] browser: String, #[case] browser_version: String, #[case] dr
println!("CLI test browser={} -- browser_version={} -- driver_version={}", browser, browser_version, driver_version);

let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.args(["--browser", &browser, "--version", &browser_version])
cmd.args(["--browser", &browser, "--browser-version", &browser_version])
.assert()
.success()
.code(0);
Expand Down

0 comments on commit 8a2e87e

Please sign in to comment.