@@ -96,6 +96,11 @@ def pytest_ignore_collect(path, config):
9696 return len ([d for d in _drivers if d .lower () in parts ]) > 0
9797
9898
99+ def pytest_generate_tests (metafunc ):
100+ if "driver" in metafunc .fixturenames and metafunc .config .option .drivers :
101+ metafunc .parametrize ("driver" , metafunc .config .option .drivers , indirect = True )
102+
103+
99104def get_driver_class (driver_option ):
100105 """Generate the driver class name from the lowercase driver option."""
101106 if driver_option == "webkitgtk" :
@@ -113,20 +118,29 @@ def get_driver_class(driver_option):
113118@pytest .fixture (scope = "function" )
114119def driver (request ):
115120 kwargs = {}
121+ driver_option = getattr (request , "param" , "Chrome" )
122+
116123 # browser can be changed with `--driver=firefox` as an argument or to addopts in pytest.ini
117- driver_class = get_driver_class (getattr (request , "param" , "Chrome" ))
118- # skip tests if not available on the platform
124+ driver_class = get_driver_class (driver_option )
125+
126+ # skip tests in the 'remote' directory if run with a local driver
127+ if request .node .path .parts [- 2 ] == "remote" and driver_class != "Remote" :
128+ pytest .skip (f"Remote tests can't be run with driver '{ driver_option } '" )
129+
130+ # skip tests that can't run on certain platforms
119131 _platform = platform .system ()
120132 if driver_class == "Safari" and _platform != "Darwin" :
121133 pytest .skip ("Safari tests can only run on an Apple OS" )
122134 if (driver_class == "Ie" ) and _platform != "Windows" :
123135 pytest .skip ("IE and EdgeHTML Tests can only run on Windows" )
124136 if "WebKit" in driver_class and _platform == "Windows" :
125137 pytest .skip ("WebKit tests cannot be run on Windows" )
138+
126139 # skip tests for drivers that don't support BiDi when --bidi is enabled
127140 if request .config .option .bidi :
128141 if driver_class in ("Ie" , "Safari" , "WebKitGTK" , "WPEWebKit" ):
129142 pytest .skip (f"{ driver_class } does not support BiDi" )
143+
130144 # conditionally mark tests as expected to fail based on driver
131145 marker = request .node .get_closest_marker (f"xfail_{ driver_class .lower ()} " )
132146
@@ -177,6 +191,7 @@ def fin():
177191 kwargs ["options" ] = options
178192
179193 driver_instance = getattr (webdriver , driver_class )(** kwargs )
194+
180195 yield driver_instance
181196 # Close the browser after BiDi tests. Those make event subscriptions
182197 # and doesn't seems to be stable enough, causing the flakiness of the
@@ -217,7 +232,6 @@ def get_options(driver_class, config):
217232 if headless :
218233 if not options :
219234 options = getattr (webdriver , f"{ driver_class } Options" )()
220-
221235 if driver_class == "Chrome" or driver_class == "Edge" :
222236 options .add_argument ("--headless=new" )
223237 if driver_class == "Firefox" :
@@ -226,7 +240,6 @@ def get_options(driver_class, config):
226240 if bidi :
227241 if not options :
228242 options = getattr (webdriver , f"{ driver_class } Options" )()
229-
230243 options .web_socket_url = True
231244 options .unhandled_prompt_behavior = "ignore"
232245
@@ -382,3 +395,11 @@ def clean_driver(request):
382395
383396 if request .node .get_closest_marker ("no_driver_after_test" ):
384397 driver_reference = None
398+
399+
400+ @pytest .fixture
401+ def firefox_options (request ):
402+ options = webdriver .FirefoxOptions ()
403+ if request .config .option .headless :
404+ options .add_argument ("-headless" )
405+ return options
0 commit comments