Skip to content

Commit

Permalink
[py] throw error when setting w3c to False #10908
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Aug 4, 2022
1 parent 1d723de commit a52bfcd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions py/selenium/webdriver/chromium/options.py
Expand Up @@ -163,6 +163,17 @@ def to_capabilities(self) -> dict:
"""
caps = self._caps
chrome_options = self.experimental_options.copy()
if 'w3c' in chrome_options:
if chrome_options['w3c']:
warnings.warn(
"Setting 'w3c: True' is redundant and will no longer be allowed",
DeprecationWarning,
stacklevel=2
)
else:
raise AttributeError('setting w3c to False is not allowed, '
'Please update to W3C Syntax: '
'https://www.selenium.dev/blog/2022/legacy-protocol-support/')
if self.mobile_options:
chrome_options.update(self.mobile_options)
chrome_options["extensions"] = self.extensions
Expand Down
25 changes: 25 additions & 0 deletions py/test/selenium/webdriver/chrome/options_tests.py
@@ -0,0 +1,25 @@
import pytest

from selenium import webdriver


def test_w3c_true():
options = webdriver.ChromeOptions()
options.add_experimental_option("w3c", True)

chrome_kwargs = {'options': options}

with pytest.warns(DeprecationWarning, match="Setting 'w3c: True' is redundant"):
driver = webdriver.Chrome(**chrome_kwargs)

driver.quit()


def test_w3c_false():
options = webdriver.ChromeOptions()
options.add_experimental_option("w3c", False)

chrome_kwargs = {'options': options}

with pytest.raises(AttributeError):
webdriver.Chrome(**chrome_kwargs)

0 comments on commit a52bfcd

Please sign in to comment.