selenium
selenium copied to clipboard
Update remote_connection.py to allow proxy_url argument
User description
There are network topologies and configurations where a proxy for the remote connection makes sense, and you do not want to set a system-wide proxy using environment variables. This small PR allows this with the smallest possible change and effort, instead of requiring users to subclass RemoteConnection, e.g.
"""A simple extension of Selenium RemoteConnection that allows a parameterized proxy instead of
solely setting a proxy via global ENV vars"""
from selenium.webdriver.remote.remote_connection import RemoteConnection
class ProxiedRemoteConnection(RemoteConnection): # pylint:disable=too-few-public-methods
"""Extends RemoteConnection to allow for a `proxy_url` parameter which is used in an
override implementation of _get_proxy_url"""
def __init__(self, remote_server_addr: str, keep_alive: bool = False, ignore_proxy: bool = False, proxy_url = None):
"""Extends RemoteConnection to allow for a `proxy_url` init parameter"""
self.__proxy_url = proxy_url
super().__init__(remote_server_addr, keep_alive, ignore_proxy)
def _get_proxy_url(self):
"""Overrides RemoteConnection to return the init `proxy_url` if supplied"""
if self.__proxy_url:
return self.__proxy_url
return super()._get_proxy_url()
Description
A non-breaking additional kwarg parameter to RemoteConnection which allows pass-in of a proxy_url to use.
Motivation and Context
There are network topologies and configurations where a proxy for the remote connection makes sense, and you do not want to set a system-wide proxy using environment variables. This small PR allows this with the smallest possible change and effort, instead of requiring users to subclass RemoteConnection
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.
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed.
PR Type
Enhancement
Description
- Introduced a new
proxy_urlparameter to theRemoteConnectionclass's__init__method, allowing users to specify a proxy URL directly. - Updated the proxy URL assignment logic to prioritize the provided
proxy_urlover the environment variable or default behavior. - This change enables more flexible network configurations without requiring system-wide proxy settings.
Changes walkthrough 📝
| Relevant files | |||
|---|---|---|---|
| Enhancement |
|
💡 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 🔵🔵⚪⚪⚪ |
| 🧪 No relevant tests |
| 🔒 No security concerns identified |
| ⚡ Key issues to review Code Clarity |
PR Code Suggestions ✨
| Category | Suggestion | Score |
| Maintainability |
Refactor the complex inline conditional assignment of
| 9 |
| Best practice |
Initialize
| 7 |
I don't think it's still valid after ClientConfig was added from release 4.26.0. Please refer to the usage of ClientConfig to add the proxy