selenium manager: check invalid browser version
User description
Thanks for contributing to Selenium! A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines. Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
Returns an error instead of downloading the possible browser version
Motivation and Context
Fix the issue https://github.com/SeleniumHQ/selenium/issues/13418
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist
- [x] I have read the contributing document.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
PR Type
Bug fix, Tests
Description
- Implemented error handling in
SeleniumManagerto return an error when an invalid browser version is provided, preventing unnecessary downloads. - Added a test case to verify the behavior when an invalid browser version is specified, ensuring the system fails gracefully.
Changes walkthrough 📝
| Relevant files | |||
|---|---|---|---|
| Error handling |
| ||
| Tests |
|
💡 PR-Agent usage: Comment
/helpon the PR to get a list of all available PR-Agent tools and their descriptions
PR Reviewer Guide 🔍
| ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪ |
| 🧪 PR contains tests |
| 🔒 No security concerns identified |
| ⚡ Key issues to review Error Handling |
PR Code Suggestions ✨
| Category | Suggestion | Score |
| Test improvement |
Verify the error message content in the test assertionEnhance the test by checking the error message content. This ensures that not only rust/tests/browser_tests.rs [167-170]
Suggestion importance[1-10]: 9Why: Enhancing the test to check the error message content ensures that the failure is not only detected but also matches the expected error message, improving the test's robustness and reliability. | 9 |
| Error handling |
Use a custom error type for more specific error handlingConsider using a more specific error type instead of
Suggestion importance[1-10]: 8Why: Using a custom error type instead of | 8 |
| Logging |
Log the error message before returning itConsider logging the error before returning it. This will help with debugging and
Suggestion importance[1-10]: 7Why: Logging the error message before returning it provides additional context in log files, which can be helpful for debugging and understanding the error's occurrence. | 7 |
This implementation is not correct since it will make Selenium Manager to fail even for valid browser versions (e.g., Chrome 127). See for example:
cargo run -- --debug --browser chrome --browser-version 127
[2024-09-19T13:58:36.355Z DEBUG] chromedriver not found in PATH
[2024-09-19T13:58:36.357Z DEBUG] chrome detected at C:\Program Files\Google\Chrome\Application\chrome.exe
[2024-09-19T13:58:36.358Z DEBUG] Running command: wmic datafile where name='C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe' get Version /value
[2024-09-19T13:58:36.521Z DEBUG] Output: "\r\r\n\r\r\nVersion=128.0.6613.138\r\r\n\r\r\n\r\r\n\r"
[2024-09-19T13:58:36.528Z DEBUG] Detected browser: chrome 128.0.6613.138
[2024-09-19T13:58:36.528Z DEBUG] Discovered chrome version (128) different to specified browser version (127)
[2024-09-19T13:58:36.529Z ERROR] Invalid version 127 provided
Also, the error message can be enhanced a bit:
return Err(anyhow!(format!(
"Invalid {} version provided: {}",
self.get_browser_name(),
major_browser_version
)));
Oops look like I didn't consider all test cases. I will take a look 😅
I reviewed this PR. I'm sorry, but it is not correct.
First, adding a call to request_fixed_browser_version_from_online like that is not a good idea. You can discover by yourself by running all the existing tests with:
cargo test
Also, the two new test cases are not adequate. First, invalid_browser_version_test() is redundant. See here. Second, the logic assessed by valid_browser_version_pass_test() is already covered by this test.
#13418 should be done with the following changes in lib.rs:
// Download browser if necessary
match self.download_browser_if_necessary(&original_browser_version) {
Ok(_) => {}
- Err(err) => self.check_error_with_driver_in_path(&use_driver_in_path, err)?,
+ Err(err) => {
+ self.set_fallback_driver_from_cache(false);
+ self.check_error_with_driver_in_path(&use_driver_in_path, err)?
+ }
}
@bonigarcia You are right. I have committed the code changes as suggested by you. Please let me know if something is missing.