Skip to content

Commit

Permalink
[rust] Clean logic for checking driver version
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Oct 3, 2023
1 parent 390fd2d commit 5e2972e
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ pub trait SeleniumManager {
browser_version
}

fn discover_driver_version(&mut self) -> Result<String, Box<dyn Error>> {
fn discover_or_download_browser_and_driver_version(
&mut self,
) -> Result<String, Box<dyn Error>> {
let mut download_browser = self.is_force_browser_download();
let major_browser_version = self.get_major_browser_version();

Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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 {} {}.*, \
Expand Down

3 comments on commit 5e2972e

@titusfortner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bonigarcia looks like this commit resulted in the Rust tests in CI to fail.

@bonigarcia
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on it

@bonigarcia
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#12877 should fix the tests broken with this change.

Please sign in to comment.