Skip to content

Commit 8815c27

Browse files
authored
[rust] Support for web proxy in Selenium Manager (#11575)
* [rust] Support for web proxy in Selenium Manager * [rust] Include CLI tests for web proxy * [rust] Include flag for network requests timeout (30 seconds by default) * [rust] Check parse error in fallback for chromedriver * [rust] Increase default request timeout to 60 seconds * [rust] Increase request timeout to 120 seconds * [rust] Improve proxy and timeout tests * [rust] Include --clear-cache and --debug in timeout test * [rust] Include test using mock proxy
1 parent 39ceed7 commit 8815c27

15 files changed

Lines changed: 1823 additions & 44 deletions

rust/Cargo.Bazel.lock

Lines changed: 1349 additions & 18 deletions
Large diffs are not rendered by default.

rust/Cargo.lock

Lines changed: 247 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "selenium-manager"
3-
version = "1.0.0-M2"
3+
version = "1.0.0-M3"
44
edition = "2021"
55
authors = ["Selenium <[email protected]"]
66
license = "Apache-2.0"
@@ -31,6 +31,7 @@ exitcode = "1.1.2"
3131
[dev-dependencies]
3232
assert_cmd = "2.0.7"
3333
rstest = "0.16.0"
34+
wiremock = "0.5.17"
3435

3536
[profile.release]
3637
opt-level = 'z' # Optimize for size

rust/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Selenium Manager can be executed using Cargo as follows:
1616

1717
```
1818
$ cargo run -- --help
19-
selenium-manager 1.0.0-M2
19+
selenium-manager 1.0.0-M3
2020
Selenium Manager is a CLI tool that automatically manages the browser/driver infrastructure required by Selenium.
2121
2222
Usage: selenium-manager [OPTIONS]
@@ -31,6 +31,10 @@ Options:
3131
Major browser version (e.g., 105, 106, etc. Also: beta, dev, canary -or nightly- is accepted)
3232
-P, --browser-path <BROWSER_PATH>
3333
Browser path (absolute) for browser version detection (e.g., /usr/bin/google-chrome, "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome", "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe")
34+
-p, --proxy <PROXY>
35+
HTTP proxy for network connection (e.g., https://myproxy.net:8080)
36+
-t, --timeout <TIMEOUT>
37+
Timeout for network requests (in seconds) [default: 120]
3438
-D, --debug
3539
Display DEBUG messages
3640
-T, --trace

rust/src/chrome.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::path::PathBuf;
2424
use crate::config::ARCH::ARM64;
2525
use crate::config::OS::{LINUX, MACOS, WINDOWS};
2626
use crate::downloads::read_content_from_link;
27-
use crate::files::{compose_driver_path_in_cache, BrowserPath};
27+
use crate::files::{compose_driver_path_in_cache, BrowserPath, PARSE_ERROR};
2828
use crate::logger::Logger;
2929
use crate::metadata::{
3030
create_driver_metadata, get_driver_version_from_metadata, get_metadata, write_metadata,
@@ -69,6 +69,10 @@ impl SeleniumManager for ChromeManager {
6969
&self.http_client
7070
}
7171

72+
fn set_http_client(&mut self, http_client: Client) {
73+
self.http_client = http_client;
74+
}
75+
7276
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str> {
7377
HashMap::from([
7478
(
@@ -180,13 +184,15 @@ impl SeleniumManager for ChromeManager {
180184
"Reading {} version from {}",
181185
&self.driver_name, driver_url
182186
));
183-
let content = read_content_from_link(self.get_http_client(), driver_url);
184-
match content {
187+
match read_content_from_link(self.get_http_client(), driver_url) {
185188
Ok(version) => {
186189
driver_version = version;
187190
break;
188191
}
189-
_ => {
192+
Err(err) => {
193+
if !err.to_string().eq(PARSE_ERROR) {
194+
return Err(err);
195+
}
190196
self.log.warn(format!(
191197
"Error getting version of {} {}. Retrying with {} {} (attempt {}/{})",
192198
&self.driver_name,

rust/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717

1818
use crate::config::OS::{LINUX, MACOS, WINDOWS};
19+
use crate::REQUEST_TIMEOUT_SEC;
1920
use std::env::consts::{ARCH, OS};
2021

2122
pub struct ManagerConfig {
@@ -24,6 +25,8 @@ pub struct ManagerConfig {
2425
pub os: String,
2526
pub arch: String,
2627
pub browser_path: String,
28+
pub proxy: String,
29+
pub timeout: u64,
2730
}
2831

2932
impl ManagerConfig {
@@ -34,6 +37,8 @@ impl ManagerConfig {
3437
os: OS.to_string(),
3538
arch: ARCH.to_string(),
3639
browser_path: "".to_string(),
40+
proxy: "".to_string(),
41+
timeout: REQUEST_TIMEOUT_SEC,
3742
}
3843
}
3944

@@ -45,6 +50,8 @@ impl ManagerConfig {
4550
os: config.os.as_str().to_string(),
4651
arch: config.arch.as_str().to_string(),
4752
browser_path: config.browser_path.as_str().to_string(),
53+
proxy: config.proxy.as_str().to_string(),
54+
timeout: config.timeout,
4855
}
4956
}
5057
}

rust/src/edge.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ impl SeleniumManager for EdgeManager {
6969
&self.http_client
7070
}
7171

72+
fn set_http_client(&mut self, http_client: Client) {
73+
self.http_client = http_client;
74+
}
75+
7276
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str> {
7377
HashMap::from([
7478
(

rust/src/files.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use zip::ZipArchive;
3232
use crate::config::OS::WINDOWS;
3333
use crate::Logger;
3434

35+
pub const PARSE_ERROR: &str = "Wrong browser/driver version";
3536
const CACHE_FOLDER: &str = ".cache/selenium";
3637
const ZIP: &str = "zip";
3738
const GZ: &str = "gz";
@@ -180,7 +181,7 @@ pub fn get_binary_extension(os: &str) -> &str {
180181

181182
pub fn parse_version(version_text: String) -> Result<String, Box<dyn Error>> {
182183
if version_text.to_ascii_lowercase().contains("error") {
183-
return Err("Wrong browser/driver version".into());
184+
return Err(PARSE_ERROR.into());
184185
}
185186
let re = Regex::new(r"[^\d^.]").unwrap();
186187
Ok(re.replace_all(&version_text, "").to_string())

rust/src/firefox.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ impl SeleniumManager for FirefoxManager {
6767
&self.http_client
6868
}
6969

70+
fn set_http_client(&mut self, http_client: Client) {
71+
self.http_client = http_client;
72+
}
73+
7074
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str> {
7175
HashMap::from([
7276
(

rust/src/iexplorer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ impl SeleniumManager for IExplorerManager {
6464
&self.http_client
6565
}
6666

67+
fn set_http_client(&mut self, http_client: Client) {
68+
self.http_client = http_client;
69+
}
70+
6771
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str> {
6872
HashMap::new()
6973
}

0 commit comments

Comments
 (0)