Skip to content

Commit 03f7be2

Browse files
committed
add and use pytest marker - webextension in tests
1 parent 0215732 commit 03f7be2

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

py/conftest.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ def pytest_addoption(parser):
8585
)
8686

8787

88+
def pytest_configure(config):
89+
"""Add custom markers for tests."""
90+
config.addinivalue_line(
91+
"markers", "webextension: mark test as requiring webextension support (for chromium based browsers)"
92+
)
93+
94+
8895
def pytest_ignore_collect(collection_path, config):
8996
drivers_opt = config.getoption("drivers")
9097
_drivers = set(drivers).difference(drivers_opt or drivers)
@@ -167,21 +174,21 @@ def fin():
167174
global driver_instance
168175
if driver_instance is None:
169176
if driver_class == "Firefox":
170-
options = get_options(driver_class, request.config)
177+
options = get_options(driver_class, request.config, request)
171178
if platform.system() == "Linux":
172179
# There are issues with window size/position when running Firefox
173180
# under Wayland, so we use XWayland instead.
174181
os.environ["MOZ_ENABLE_WAYLAND"] = "0"
175182
if driver_class == "Chrome":
176-
options = get_options(driver_class, request.config)
183+
options = get_options(driver_class, request.config, request)
177184
if driver_class == "Edge":
178-
options = get_options(driver_class, request.config)
185+
options = get_options(driver_class, request.config, request)
179186
if driver_class == "WebKitGTK":
180-
options = get_options(driver_class, request.config)
187+
options = get_options(driver_class, request.config, request)
181188
if driver_class == "WPEWebKit":
182-
options = get_options(driver_class, request.config)
189+
options = get_options(driver_class, request.config, request)
183190
if driver_class == "Remote":
184-
options = get_options("Firefox", request.config) or webdriver.FirefoxOptions()
191+
options = get_options("Firefox", request.config, request) or webdriver.FirefoxOptions()
185192
options.set_capability("moz:firefoxOptions", {})
186193
options.enable_downloads = True
187194
if driver_path is not None:
@@ -210,7 +217,7 @@ def fin():
210217
driver_instance = None
211218

212219

213-
def get_options(driver_class, config):
220+
def get_options(driver_class, config, request=None):
214221
browser_path = config.option.binary
215222
browser_args = config.option.args
216223
headless = config.option.headless
@@ -237,8 +244,13 @@ def get_options(driver_class, config):
237244
options.web_socket_url = True
238245
options.unhandled_prompt_behavior = "ignore"
239246

240-
# Enable webextensions for Chromium-based browsers when BiDi is enabled
241-
if driver_class in ("Chrome", "Edge") and hasattr(options, "enable_webextensions"):
247+
# Only enable webextensions for Chromium-based browsers when the test is marked with @pytest.mark.webextension
248+
if (
249+
request
250+
and request.node.get_closest_marker("webextension")
251+
and driver_class in ("Chrome", "Edge")
252+
and hasattr(options, "enable_webextensions")
253+
):
242254
options.enable_webextensions = True
243255

244256
return options
@@ -358,7 +370,7 @@ def clean_service(request):
358370
@pytest.fixture(scope="function")
359371
def clean_options(request):
360372
driver_class = get_driver_class(request.config.option.drivers[0])
361-
yield get_options(driver_class, request.config)
373+
yield get_options(driver_class, request.config, request)
362374

363375

364376
@pytest.fixture

py/test/selenium/webdriver/common/bidi_webextension_tests.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ def test_webextension_initialized(driver):
6060
assert driver.webextension is not None
6161

6262

63+
@pytest.mark.webextension
6364
def test_install_extension_path(driver, pages):
6465
"""Test installing an extension from a directory path.
6566
66-
Note: For Chrome and Edge, webextensions are enabled when BiDi is used from conftest.py for this test.
67+
Note: For Chrome and Edge, webextensions are enabled when the test is marked with @pytest.mark.webextension.
6768
You can also manually enable them using:
6869
6970
from selenium.webdriver.chrome.options import Options
@@ -121,6 +122,7 @@ def test_install_base64_extension_path(driver, pages):
121122
uninstall_extension_and_verify_extension_uninstalled(driver, ext_info)
122123

123124

125+
@pytest.mark.webextension
124126
def test_install_unsigned_extension(driver, pages):
125127
"""Test installing an unsigned extension."""
126128
path = os.path.join(extensions, "webextensions-selenium-example")
@@ -133,6 +135,7 @@ def test_install_unsigned_extension(driver, pages):
133135
uninstall_extension_and_verify_extension_uninstalled(driver, ext_info)
134136

135137

138+
@pytest.mark.webextension
136139
def test_install_with_extension_id_uninstall(driver, pages):
137140
"""Test uninstalling an extension using just the extension ID."""
138141
path = os.path.join(extensions, EXTENSION_PATH)

0 commit comments

Comments
 (0)