Skip to content

Commit 93e6281

Browse files
committed
[rust] Refactor driver URL logic in iexplorer module
1 parent cb2560d commit 93e6281

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

rust/src/iexplorer.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub struct IExplorerManager {
5252
pub config: ManagerConfig,
5353
pub http_client: Client,
5454
pub log: Logger,
55+
pub driver_url: Option<String>,
5556
}
5657

5758
impl IExplorerManager {
@@ -67,6 +68,7 @@ impl IExplorerManager {
6768
http_client: create_http_client(default_timeout, default_proxy)?,
6869
config,
6970
log: Logger::default(),
71+
driver_url: None,
7072
}))
7173
}
7274
}
@@ -132,9 +134,7 @@ impl SeleniumManager for IExplorerManager {
132134
.filter(|url| url.browser_download_url.contains(IEDRIVER_RELEASE))
133135
.collect();
134136
let driver_url = &driver_releases.last().unwrap().browser_download_url;
135-
RELEASE_URL.with(|url| {
136-
*url.borrow_mut() = driver_url.to_string();
137-
});
137+
self.driver_url = Some(driver_url.to_string());
138138

139139
let index_release =
140140
driver_url.rfind(IEDRIVER_RELEASE).unwrap() + IEDRIVER_RELEASE.len();
@@ -163,30 +163,27 @@ impl SeleniumManager for IExplorerManager {
163163
}
164164

165165
fn get_driver_url(&mut self) -> Result<String, Box<dyn Error>> {
166-
let mut driver_url = "".to_string();
167-
RELEASE_URL.with(|url| {
168-
driver_url = url.borrow().to_string();
169-
});
170-
if driver_url.is_empty() {
171-
let driver_version = self.get_driver_version();
172-
let mut release_version = driver_version.to_string();
173-
if !driver_version.ends_with('0') {
174-
// E.g.: version 4.8.1 is shipped within release 4.8.0
175-
let error_message = format!(
176-
"Wrong {} version: '{}'",
177-
self.get_driver_name(),
178-
driver_version
179-
);
180-
let index = release_version.rfind('.').ok_or(error_message)? + 1;
181-
release_version = release_version[..index].to_string();
182-
release_version.push('0');
183-
}
184-
driver_url = format!(
185-
"{}download/selenium-{}/{}{}.zip",
186-
DRIVER_URL, release_version, IEDRIVER_RELEASE, driver_version
166+
if self.driver_url.is_some() {
167+
return Ok(self.driver_url.as_ref().unwrap().to_string());
168+
}
169+
170+
let driver_version = self.get_driver_version();
171+
let mut release_version = driver_version.to_string();
172+
if !driver_version.ends_with('0') {
173+
// E.g.: version 4.8.1 is shipped within release 4.8.0
174+
let error_message = format!(
175+
"Wrong {} version: '{}'",
176+
self.get_driver_name(),
177+
driver_version
187178
);
179+
let index = release_version.rfind('.').ok_or(error_message)? + 1;
180+
release_version = release_version[..index].to_string();
181+
release_version.push('0');
188182
}
189-
Ok(driver_url)
183+
Ok(format!(
184+
"{}download/selenium-{}/{}{}.zip",
185+
DRIVER_URL, release_version, IEDRIVER_RELEASE, driver_version
186+
))
190187
}
191188

192189
fn get_driver_path_in_cache(&self) -> PathBuf {

0 commit comments

Comments
 (0)