From 5e2972e0db7a361c0291c4917fe0098c6db39536 Mon Sep 17 00:00:00 2001 From: Boni Garcia Date: Tue, 3 Oct 2023 14:07:22 +0200 Subject: [PATCH] [rust] Clean logic for checking driver version --- rust/src/lib.rs | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index e2f2649242bcf..9d1a12bfecaf3 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -281,7 +281,9 @@ pub trait SeleniumManager { browser_version } - fn discover_driver_version(&mut self) -> Result> { + fn discover_or_download_browser_and_driver_version( + &mut self, + ) -> Result> { let mut download_browser = self.is_force_browser_download(); let major_browser_version = self.get_major_browser_version(); @@ -526,22 +528,23 @@ pub trait SeleniumManager { } } - // Discover proper driver version - if self.get_driver_version().is_empty() { - match self.discover_driver_version() { - Ok(driver_version) => { + // Discover browser version (or download it, if not available and possible). + // With the found browser version, discover the proper driver version using online endpoints + match self.discover_or_download_browser_and_driver_version() { + Ok(driver_version) => { + if self.get_driver_version().is_empty() { self.set_driver_version(driver_version); } - Err(err) => { - if driver_in_path_version.is_some() { - self.get_logger().warn(format!( - "Exception managing {}: {}", - self.get_browser_name(), - err - )); - } else { - return Err(err); - } + } + Err(err) => { + if driver_in_path_version.is_some() && driver_in_path.is_some() { + self.get_logger().warn(format!( + "Exception managing {}: {}", + self.get_browser_name(), + err + )); + } else { + return Err(err); } } } @@ -550,12 +553,9 @@ pub trait SeleniumManager { if let (Some(version), Some(path)) = (&driver_in_path_version, &driver_in_path) { // If proper driver version is not the same as the driver in path, display warning let major_version = self.get_major_version(version)?; - let driver_condition = if self.is_firefox() { - !version.eq(self.get_driver_version()) - } else { - !major_version.eq(&self.get_major_browser_version()) - }; - if !self.get_driver_version().is_empty() && driver_condition { + if (self.is_firefox() && !version.eq(self.get_driver_version())) + || !major_version.eq(&self.get_major_browser_version()) + { self.get_logger().warn(format!( "The {} version ({}) detected in PATH at {} might not be compatible with \ the detected {} version ({}); currently, {} {} is recommended for {} {}.*, \