@@ -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+
8895def 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" )
359371def 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
0 commit comments