Skip to content

Commit 6f77a1e

Browse files
committed
[py]: Deprecate non W3C capability implicit conversion
1 parent d1818d7 commit 6f77a1e

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

py/selenium/webdriver/remote/webdriver.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
'platform': 'platformName'
7676
}
7777

78-
7978
cdp = None
8079

8180

@@ -104,7 +103,11 @@ def _make_w3c_caps(caps):
104103
caps['proxy']['proxyType'] = caps['proxy']['proxyType'].lower()
105104
for k, v in caps.items():
106105
if v and k in _OSS_W3C_CONVERSION:
107-
always_match[_OSS_W3C_CONVERSION[k]] = v.lower() if k == 'platform' else v
106+
# Todo: Remove in 4.7.0 (Deprecated in 4.5.0)
107+
w3c_equivalent = _OSS_W3C_CONVERSION[k]
108+
warnings.warn(f"{k} is not a w3c capability. use `{w3c_equivalent}` instead. This will no longer be"
109+
f" converted in 4.7.0", DeprecationWarning, stacklevel=2)
110+
always_match[w3c_equivalent] = v.lower() if k == 'platform' else v
108111
if k in _W3C_CAPABILITY_NAMES or ':' in k:
109112
always_match[k] = v
110113
if profile:
@@ -1191,7 +1194,8 @@ def _get_cdp_details(self):
11911194
http = urllib3.PoolManager()
11921195
_firefox = False
11931196
if self.caps.get("browserName") == "chrome":
1194-
debugger_address = self.caps.get(f"{self.vendor_prefix}:{self.caps.get('browserName')}Options").get("debuggerAddress")
1197+
debugger_address = self.caps.get(f"{self.vendor_prefix}:{self.caps.get('browserName')}Options").get(
1198+
"debuggerAddress")
11951199
else:
11961200
_firefox = True
11971201
debugger_address = self.caps.get("moz:debuggerAddress")

py/test/unit/selenium/webdriver/remote/new_session_tests.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import pytest
2323

2424
from selenium.webdriver import DesiredCapabilities
25+
from selenium.webdriver.remote import webdriver
2526
from selenium.webdriver.remote.command import Command
2627
from selenium.webdriver.remote.webdriver import WebDriver
27-
from selenium.webdriver.remote import webdriver
2828

2929

3030
def test_converts_oss_capabilities_to_w3c(mocker):
@@ -36,6 +36,17 @@ def test_converts_oss_capabilities_to_w3c(mocker):
3636
mock.assert_called_with(Command.NEW_SESSION, expected_params)
3737

3838

39+
@pytest.mark.parametrize("oss_name, val, w3c_name", (
40+
('acceptSslCerts', True, 'acceptInsecureCerts'),
41+
("version", '11', "browserVersion"),
42+
("platform", 'windows', 'platformName')))
43+
def test_non_compliant_w3c_caps_is_deprecated(oss_name, val, w3c_name):
44+
from selenium.webdriver.remote.webdriver import _make_w3c_caps
45+
msg = f"{oss_name} is not a w3c capability. use `{w3c_name}` instead. This will no longer be converted in 4.7.0"
46+
with pytest.warns(DeprecationWarning, match=msg):
47+
_ = _make_w3c_caps({oss_name: val})
48+
49+
3950
def test_converts_proxy_type_value_to_lowercase_for_w3c(mocker):
4051
mock = mocker.patch('selenium.webdriver.remote.webdriver.WebDriver.execute')
4152
oss_caps = {'proxy': {'proxyType': 'MANUAL', 'httpProxy': 'foo'}}

0 commit comments

Comments
 (0)