Skip to content

Commit 5b40670

Browse files
authored
[py] support Proxies with Selenium Manager (#12032)
1 parent 6a776f3 commit 5b40670

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

py/selenium/webdriver/common/selenium_manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ def driver_location(self, options: BaseOptions) -> str:
8585
args.append("--browser-path")
8686
args.append(str(binary_location))
8787

88+
proxy = options.proxy
89+
if proxy and (proxy.http_proxy or proxy.ssl_proxy):
90+
args.append("--proxy")
91+
value = proxy.ssl_proxy if proxy.sslProxy else proxy.http_proxy
92+
args.append(value)
93+
8894
if logger.getEffectiveLevel() == logging.DEBUG:
8995
args.append("--debug")
9096

py/test/selenium/webdriver/common/selenium_manager_tests.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from selenium.common.exceptions import SeleniumManagerException
2323
from selenium.webdriver.chrome.options import Options
24+
from selenium.webdriver.common.proxy import Proxy
2425
from selenium.webdriver.common.selenium_manager import SeleniumManager
2526

2627

@@ -62,6 +63,27 @@ def test_browser_path_is_used_for_sm(mocker):
6263
assert "/opt/bin/browser-bin" in args[0]
6364

6465

66+
def test_proxy_is_used_for_sm(mocker):
67+
import subprocess
68+
69+
mock_run = mocker.patch("subprocess.run")
70+
mocked_result = Mock()
71+
mocked_result.configure_mock(
72+
**{"stdout.decode.return_value": '{"result": {"message": "driver"}, "logs": []}', "returncode": 0}
73+
)
74+
mock_run.return_value = mocked_result
75+
options = Options()
76+
options.capabilities["browserName"] = "chrome"
77+
proxy = Proxy()
78+
proxy.http_proxy = "http-proxy"
79+
options.proxy = proxy
80+
81+
_ = SeleniumManager().driver_location(options)
82+
args, kwargs = subprocess.run.call_args
83+
assert "--proxy" in args[0]
84+
assert "http-proxy" in args[0]
85+
86+
6587
def test_stderr_is_propagated_to_exception_messages():
6688
msg = r"Selenium Manager failed for:.* --browser foo --output json\.\nInvalid browser name: foo\n"
6789
with pytest.raises(SeleniumManagerException, match=msg):

0 commit comments

Comments
 (0)