Skip to content

[rust] Honor full chromedriver version if specified (#17298)#17361

Merged
bonigarcia merged 3 commits into
trunkfrom
sm_fixed_driver_version
May 5, 2026
Merged

[rust] Honor full chromedriver version if specified (#17298)#17361
bonigarcia merged 3 commits into
trunkfrom
sm_fixed_driver_version

Conversation

@bonigarcia

Copy link
Copy Markdown
Member

🔗 Related Issues

Fixes #17298

💥 What does this PR do?

This PR makes SM to honor the full driver version if specified. For example, before this PR (see the difference with respect to the driver version specified 144.0.7500.0, and the actual version downloaded, 144.0.7559.133):

selenium-manager --browser chrome --debug --clear-cache --driver-version 144.0.7500.0
[2026-04-18T20:51:25.069Z DEBUG] Clearing cache at: C:\Users\boni\.cache\selenium
[2026-04-18T20:51:25.113Z DEBUG] chromedriver not found in PATH
[2026-04-18T20:51:25.114Z DEBUG] chrome detected at C:\Program Files\Google\Chrome\Application\chrome.exe
[2026-04-18T20:51:25.114Z DEBUG] Detected browser: chrome 147.0.7727.56
[2026-04-18T20:51:25.116Z DEBUG] Acquiring lock: C:\Users\boni\.cache\selenium\chromedriver\win64\144.0.7500.0\sm.lock
[2026-04-18T20:51:25.117Z DEBUG] Discovering versions from https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
[2026-04-18T20:51:35.103Z DEBUG] Downloading chromedriver 144.0.7500.0 from https://storage.googleapis.com/chrome-for-testing-public/144.0.7559.133/win64/chromedriver-win64.zip
[2026-04-18T20:52:08.152Z INFO ] Driver path: C:\Users\boni\.cache\selenium\chromedriver\win64\144.0.7500.0\chromedriver.exe
[2026-04-18T20:52:08.152Z INFO ] Browser path: C:\Program Files\Google\Chrome\Application\chrome.exe

With this PR:

selenium-manager --browser chrome --debug --clear-cache --driver-version 144.0.7500.0
[2026-04-18T20:58:05.518Z DEBUG] Clearing cache at: C:\Users\boni\.cache\selenium
[2026-04-18T20:58:05.544Z DEBUG] chromedriver not found in PATH
[2026-04-18T20:58:05.545Z DEBUG] chrome detected at C:\Program Files\Google\Chrome\Application\chrome.exe
[2026-04-18T20:58:05.546Z DEBUG] Detected browser: chrome 147.0.7727.56
[2026-04-18T20:58:05.548Z DEBUG] Acquiring lock: C:\Users\boni\.cache\selenium\chromedriver\win64\144.0.7500.0\sm.lock
[2026-04-18T20:58:05.549Z DEBUG] Discovering versions from https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
[2026-04-18T20:58:14.164Z DEBUG] Downloading chromedriver 144.0.7500.0 from https://storage.googleapis.com/chrome-for-testing-public/144.0.7500.0/win64/chromedriver-win64.zip
[2026-04-18T20:58:45.901Z INFO ] Driver path: C:\Users\boni\.cache\selenium\chromedriver\win64\144.0.7500.0\chromedriver.exe
[2026-04-18T20:58:45.901Z INFO ] Browser path: C:\Program Files\Google\Chrome\Application\chrome.exe

🔧 Implementation Notes

💡 Additional Considerations

🔄 Types of changes

  • Bug fix (backwards compatible)

@selenium-ci selenium-ci added C-rust Rust code is mostly Selenium Manager B-manager Selenium Manager labels Apr 18, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Honor full chromedriver version if specified

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Honor full chromedriver version when explicitly specified
• Add helper method to check if driver version is specific
• Fix version filtering logic to use full version string
• Prevent unnecessary major version extraction for explicit versions

Grey Divider

File Changes

1. rust/src/chrome.rs 🐞 Bug fix +9/-5

Fix chromedriver version filtering logic

• Modified request_good_driver_version_from_online() to check if driver version is explicitly
 specified
• When driver version is specific, use it directly without extracting major version
• Updated version filtering to use string reference instead of owned string
• Improved logic flow to distinguish between explicit and inferred versions

rust/src/chrome.rs


2. rust/src/lib.rs ✨ Enhancement +4/-0

Add driver version specificity check method

• Added new is_driver_version_specific() method to SeleniumManager trait
• Method checks if driver version contains dots (indicating specific version)
• Mirrors existing is_browser_version_specific() pattern

rust/src/lib.rs


Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Missing Chrome --driver-version test 📘 Rule violation ☼ Reliability
Description
The driver-version selection logic for Chrome now changes behavior by filtering on the full driver
version when it is version-specific, but there is no positive test asserting this observable
behavior. This risks regressions where Selenium Manager again downloads a different chromedriver
version than the one specified.
Code

rust/src/chrome.rs[R174-186]

+        let version_for_filtering = if self.is_driver_version_specific() {
            self.get_driver_version()
+        } else {
+            let browser_or_driver_version = if self.get_driver_version().is_empty() {
+                self.get_browser_version()
+            } else {
+                self.get_driver_version()
+            };
+            &self.get_major_version(browser_or_driver_version)?
        };
-        let version_for_filtering = self.get_major_version(browser_or_driver_version)?;
        self.log.trace(format!(
            "Driver version used to request CfT: {version_for_filtering}"
        ));
Evidence
PR Compliance ID 9 requires adding/updating unit tests for observable behavior changes. The change
in request_good_driver_version_from_online() alters how chromedriver versions are
filtered/selected (full version vs major), while existing integration tests exercise Chrome with
--browser-version or only validate error handling for --driver-version, not successful Chrome
--driver-version resolution.

rust/src/chrome.rs[174-195]
rust/tests/browser_tests.rs[27-95]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Chrome now honors a fully specified chromedriver version by filtering known-good versions using the full version string. This is an observable behavior change but there is no test that asserts successful resolution/download selection for Chrome when `--driver-version` is provided.

## Issue Context
The change is in `ChromeManager::request_good_driver_version_from_online()`, which now uses `is_driver_version_specific()` to decide whether to filter by the full driver version vs the major version.

## Fix Focus Areas
- rust/src/chrome.rs[174-195]
- rust/src/lib.rs[819-821]
- rust/tests/browser_tests.rs[27-95]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Dangling version reference🐞 Bug ≡ Correctness
Description
ChromeManager::request_good_driver_version_from_online can set version_for_filtering to a
reference to the temporary String returned by get_major_version(), which is dropped at the end
of the if expression and fails to compile. Additionally, `format_three_args(...,
&version_for_filtering, ...) now passes &&str because version_for_filtering` is inferred as
&str, causing another compile-time type mismatch.
Code

rust/src/chrome.rs[R174-186]

+        let version_for_filtering = if self.is_driver_version_specific() {
            self.get_driver_version()
+        } else {
+            let browser_or_driver_version = if self.get_driver_version().is_empty() {
+                self.get_browser_version()
+            } else {
+                self.get_driver_version()
+            };
+            &self.get_major_version(browser_or_driver_version)?
        };
-        let version_for_filtering = self.get_major_version(browser_or_driver_version)?;
        self.log.trace(format!(
            "Driver version used to request CfT: {version_for_filtering}"
        ));
Evidence
get_driver_version() returns &str, so the if expression forces version_for_filtering to be
&str. In the else branch you borrow the temporary String returned by get_major_version()
(&self.get_major_version(...)), which cannot outlive the if expression. Separately,
format_three_args requires &str arguments, but &version_for_filtering becomes &&str once
version_for_filtering: &str.

rust/src/chrome.rs[173-203]
rust/src/lib.rs[1087-1089]
rust/src/lib.rs[1380-1382]
rust/src/lib.rs[1745-1749]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`version_for_filtering` is inferred as `&str` (because `get_driver_version()` returns `&str`), but the `else` branch returns `&self.get_major_version(...)` where `get_major_version` returns a fresh `String`. This creates a reference to a temporary and fails compilation. Also, `format_three_args(..., &version_for_filtering, ...)` now passes `&&str`.

### Issue Context
You need `version_for_filtering` to live long enough for logging/filtering/error formatting. The simplest fix is to make it an owned `String` in both branches.

### Fix Focus Areas
- rust/src/chrome.rs[173-203]

### Suggested change
- Change `version_for_filtering` to be a `String`:
 - `if self.is_driver_version_specific() { self.get_driver_version().to_string() } else { self.get_major_version(browser_or_driver_version)? }`
- Update usage sites:
 - `starts_with(version_for_filtering.as_str())`
 - `format_three_args(..., version_for_filtering.as_str(), ...)` (remove the extra `&`)

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@bonigarcia bonigarcia removed the B-manager Selenium Manager label Apr 18, 2026
Comment thread rust/src/chrome.rs
Comment thread rust/src/chrome.rs
@bonigarcia bonigarcia enabled auto-merge (squash) May 5, 2026 09:32
@bonigarcia bonigarcia disabled auto-merge May 5, 2026 09:32
@bonigarcia bonigarcia merged commit 305bab6 into trunk May 5, 2026
66 of 67 checks passed
@bonigarcia bonigarcia deleted the sm_fixed_driver_version branch May 5, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-rust Rust code is mostly Selenium Manager

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🚀 Feature]: Enable specifying exact version of ChromeDriver

2 participants