Skip to content

Commit

Permalink
[rust] Read browser_ttl and driver_ttl from CLI flags
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Jun 16, 2023
1 parent eb23213 commit bf38914
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions rust/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ impl SeleniumManager for ChromeManager {
let browser_version_binding = self.get_major_browser_version();
let browser_version = browser_version_binding.as_str();
let mut metadata = get_metadata(self.get_logger());
let driver_ttl = self.get_config().driver_ttl;

match get_driver_version_from_metadata(&metadata.drivers, self.driver_name, browser_version)
{
Expand Down Expand Up @@ -336,7 +335,8 @@ impl SeleniumManager for ChromeManager {
self.request_good_version_from_cft()?
};

if !browser_version.is_empty() && !driver_version.is_empty() {
let driver_ttl = self.get_driver_ttl();
if driver_ttl > 0 && !browser_version.is_empty() && !driver_version.is_empty() {
metadata.drivers.push(create_driver_metadata(
browser_version,
self.driver_name,
Expand Down
4 changes: 2 additions & 2 deletions rust/src/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ impl SeleniumManager for EdgeManager {
fn request_driver_version(&mut self) -> Result<String, Box<dyn Error>> {
let mut browser_version = self.get_major_browser_version();
let mut metadata = get_metadata(self.get_logger());
let driver_ttl = self.get_config().driver_ttl;

match get_driver_version_from_metadata(
&metadata.drivers,
Expand Down Expand Up @@ -211,7 +210,8 @@ impl SeleniumManager for EdgeManager {
let driver_version =
read_version_from_link(self.get_http_client(), driver_url, self.get_logger())?;

if !browser_version.is_empty() {
let driver_ttl = self.get_driver_ttl();
if driver_ttl > 0 && !browser_version.is_empty() {
metadata.drivers.push(create_driver_metadata(
browser_version.as_str(),
self.driver_name,
Expand Down
4 changes: 2 additions & 2 deletions rust/src/firefox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ impl SeleniumManager for FirefoxManager {
let browser_version_binding = self.get_major_browser_version();
let browser_version = browser_version_binding.as_str();
let mut metadata = get_metadata(self.get_logger());
let driver_ttl = self.get_config().driver_ttl;

match get_driver_version_from_metadata(&metadata.drivers, self.driver_name, browser_version)
{
Expand All @@ -182,7 +181,8 @@ impl SeleniumManager for FirefoxManager {
let driver_version =
read_redirect_from_link(self.get_http_client(), latest_url, self.get_logger())?;

if !browser_version.is_empty() {
let driver_ttl = self.get_driver_ttl();
if driver_ttl > 0 && !browser_version.is_empty() {
metadata.drivers.push(create_driver_metadata(
browser_version,
self.driver_name,
Expand Down
4 changes: 2 additions & 2 deletions rust/src/iexplorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ impl SeleniumManager for IExplorerManager {
let browser_version_binding = self.get_major_browser_version();
let browser_version = browser_version_binding.as_str();
let mut metadata = get_metadata(self.get_logger());
let driver_ttl = self.get_config().driver_ttl;

match get_driver_version_from_metadata(&metadata.drivers, self.driver_name, browser_version)
{
Expand Down Expand Up @@ -144,7 +143,8 @@ impl SeleniumManager for IExplorerManager {
self.get_logger(),
)?;

if !browser_version.is_empty() {
let driver_ttl = self.get_driver_ttl();
if driver_ttl > 0 && !browser_version.is_empty() {
metadata.drivers.push(create_driver_metadata(
browser_version,
self.driver_name,
Expand Down
21 changes: 19 additions & 2 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ pub trait SeleniumManager {
fn detect_browser_version(&self, commands: Vec<String>) -> Option<String> {
let mut metadata = get_metadata(self.get_logger());
let browser_name = &self.get_browser_name();
let browser_ttl = self.get_config().browser_ttl;

match get_browser_version_from_metadata(&metadata.browsers, browser_name) {
Some(version) => {
Expand Down Expand Up @@ -182,7 +181,9 @@ pub trait SeleniumManager {
browser_version = Some(full_browser_version);
break;
}
if browser_version.is_some() && !self.is_safari() {

let browser_ttl = self.get_browser_ttl();
if browser_ttl > 0 && browser_version.is_some() && !self.is_safari() {
metadata.browsers.push(create_browser_metadata(
browser_name,
browser_version.as_ref().unwrap(),
Expand Down Expand Up @@ -455,6 +456,22 @@ pub trait SeleniumManager {
self.set_http_client(http_client);
Ok(())
}

fn get_driver_ttl(&self) -> u64 {
self.get_config().driver_ttl
}

fn set_driver_ttl(&mut self, driver_ttl: u64) {
self.get_config_mut().driver_ttl = driver_ttl;
}

fn get_browser_ttl(&self) -> u64 {
self.get_config().browser_ttl
}

fn set_browser_ttl(&mut self, browser_ttl: u64) {
self.get_config_mut().browser_ttl = browser_ttl;
}
}

// ----------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ fn main() {
selenium_manager.set_browser_version(cli.browser_version.unwrap_or_default());
selenium_manager.set_driver_version(cli.driver_version.unwrap_or_default());
selenium_manager.set_browser_path(cli.browser_path.unwrap_or_default());
selenium_manager.set_driver_ttl(cli.driver_ttl);
selenium_manager.set_browser_ttl(cli.browser_ttl);

selenium_manager
.set_timeout(cli.timeout)
Expand Down

0 comments on commit bf38914

Please sign in to comment.