You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As explained in #14045 the goal of this PR is to provide users with an alternative option to set the path to their own drivers if they do not want to use selenium manager
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Potential Bug The env_path() method returns None if the environment variable is not set, which could lead to unexpected behavior if not handled properly in the calling code.
Code Duplication The logic for setting the service path is duplicated across different webdriver implementations (Chrome, Firefox, IE, Safari). Consider refactoring this into a common method.
def env_path(self) -> Optional[str]:
+ """+ Retrieve the driver path from the environment variable.++ Returns:+ Optional[str]: The driver path if set in the environment, None otherwise.+ """
return os.getenv(self.DRIVER_PATH_ENV_KEY, None)
Apply this suggestion
Suggestion importance[1-10]: 9
Why: Providing a docstring significantly improves code documentation, helping developers understand the method's purpose and return value, which is crucial for maintainability.
9
Enhancement
Add a type hint for the driver_path_env_key parameter in the constructor
Consider adding a type hint for the driver_path_env_key parameter in the init method to improve code readability and maintainability.
Why: Adding a type hint enhances code readability and maintainability, making it clear that the parameter is optional and expected to be a string.
8
Rename the environment variable key attribute for better clarity and consistency
Consider using a more descriptive name for the environment variable key attribute. Instead of DRIVER_PATH_ENV_KEY, a name like driver_path_env_var might be clearer and more consistent with Python naming conventions.
Why: The suggestion improves code readability by using a more descriptive and consistent naming convention, which is beneficial for maintainability.
7
Maintainability
Add a comment to explain the fallback mechanism for setting the service path
Consider adding a comment to explain the fallback mechanism when setting the self.service.path. This will help other developers understand the logic behind using both env_path() and finder.get_driver_path().
+# Use the path from environment variable if set, otherwise use the path found by DriverFinder
self.service.path = self.service.env_path() or finder.get_driver_path()
Apply this suggestion
Suggestion importance[1-10]: 6
Why: The comment clarifies the logic behind the fallback mechanism, aiding in code comprehension and future maintenance, though it is not critical.
Follow up to PR SeleniumHQ#14528, to avoid `os.getenv` raising `TypeError`
in `env_path` when `driver_path_env_key` is not passed to `Service`
constructor.
Follow up to PR SeleniumHQ#14528, to avoid `os.getenv` raising `TypeError`
in `env_path` when `driver_path_env_key` is not passed to `Service`
constructor.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Allows using custom driver paths using ENV variables
Implements the functionality from the Ruby port in commit 7602371#diff-076503247734547bc24938fcc3aa2b317890093dae9376e32ac9b1e41b7037f9
Motivation and Context
As explained in #14045 the goal of this PR is to provide users with an alternative option to set the path to their own drivers if they do not want to use selenium manager
Types of changes
Checklist
PS: Thanks to @Animesh-Ghosh and @aguspe for the help 🚀
PR Type
Enhancement, Tests
Description
driver_path_env_key
to specify the environment variable key for driver paths.env_path
method in theService
class to fetch driver paths from environment variables.Changes walkthrough 📝
10 files
service.py
Add environment variable support for ChromeDriver path
py/selenium/webdriver/chromium/service.py
driver_path_env_key
parameter to the constructor.webdriver.py
Use environment variable for Chromium driver path
py/selenium/webdriver/chromium/webdriver.py
service.py
Implement environment variable path support in Service
py/selenium/webdriver/common/service.py
driver_path_env_key
parameter to the constructor.env_path
method to fetch path from environment variable.service.py
Add environment variable support for EdgeDriver path
py/selenium/webdriver/edge/service.py
driver_path_env_key
parameter to the constructor.service.py
Add environment variable support for GeckoDriver path
py/selenium/webdriver/firefox/service.py
driver_path_env_key
parameter to the constructor.webdriver.py
Use environment variable for Firefox driver path
py/selenium/webdriver/firefox/webdriver.py
service.py
Add environment variable support for IEDriver path
py/selenium/webdriver/ie/service.py
driver_path_env_key
parameter to the constructor.webdriver.py
Use environment variable for IE driver path
py/selenium/webdriver/ie/webdriver.py
service.py
Add environment variable support for SafariDriver path
py/selenium/webdriver/safari/service.py
driver_path_env_key
parameter to the constructor.webdriver.py
Use environment variable for Safari driver path
py/selenium/webdriver/safari/webdriver.py
2 files
chrome_service_tests.py
Add tests for ChromeDriver path from environment variable
py/test/selenium/webdriver/chrome/chrome_service_tests.py
firefox_service_tests.py
Add tests for GeckoDriver path from environment variable
py/test/selenium/webdriver/firefox/firefox_service_tests.py