Skip to content

Commit a52bfcd

Browse files
committed
[py] throw error when setting w3c to False #10908
1 parent 1d723de commit a52bfcd

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

py/selenium/webdriver/chromium/options.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ def to_capabilities(self) -> dict:
163163
"""
164164
caps = self._caps
165165
chrome_options = self.experimental_options.copy()
166+
if 'w3c' in chrome_options:
167+
if chrome_options['w3c']:
168+
warnings.warn(
169+
"Setting 'w3c: True' is redundant and will no longer be allowed",
170+
DeprecationWarning,
171+
stacklevel=2
172+
)
173+
else:
174+
raise AttributeError('setting w3c to False is not allowed, '
175+
'Please update to W3C Syntax: '
176+
'https://www.selenium.dev/blog/2022/legacy-protocol-support/')
166177
if self.mobile_options:
167178
chrome_options.update(self.mobile_options)
168179
chrome_options["extensions"] = self.extensions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
3+
from selenium import webdriver
4+
5+
6+
def test_w3c_true():
7+
options = webdriver.ChromeOptions()
8+
options.add_experimental_option("w3c", True)
9+
10+
chrome_kwargs = {'options': options}
11+
12+
with pytest.warns(DeprecationWarning, match="Setting 'w3c: True' is redundant"):
13+
driver = webdriver.Chrome(**chrome_kwargs)
14+
15+
driver.quit()
16+
17+
18+
def test_w3c_false():
19+
options = webdriver.ChromeOptions()
20+
options.add_experimental_option("w3c", False)
21+
22+
chrome_kwargs = {'options': options}
23+
24+
with pytest.raises(AttributeError):
25+
webdriver.Chrome(**chrome_kwargs)

0 commit comments

Comments
 (0)