@@ -96,6 +96,11 @@ def pytest_ignore_collect(path, config):
96
96
return len ([d for d in _drivers if d .lower () in parts ]) > 0
97
97
98
98
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
+
99
104
def get_driver_class (driver_option ):
100
105
"""Generate the driver class name from the lowercase driver option."""
101
106
if driver_option == "webkitgtk" :
@@ -113,20 +118,29 @@ def get_driver_class(driver_option):
113
118
@pytest .fixture (scope = "function" )
114
119
def driver (request ):
115
120
kwargs = {}
121
+ driver_option = getattr (request , "param" , "Chrome" )
122
+
116
123
# 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
119
131
_platform = platform .system ()
120
132
if driver_class == "Safari" and _platform != "Darwin" :
121
133
pytest .skip ("Safari tests can only run on an Apple OS" )
122
134
if (driver_class == "Ie" ) and _platform != "Windows" :
123
135
pytest .skip ("IE and EdgeHTML Tests can only run on Windows" )
124
136
if "WebKit" in driver_class and _platform == "Windows" :
125
137
pytest .skip ("WebKit tests cannot be run on Windows" )
138
+
126
139
# skip tests for drivers that don't support BiDi when --bidi is enabled
127
140
if request .config .option .bidi :
128
141
if driver_class in ("Ie" , "Safari" , "WebKitGTK" , "WPEWebKit" ):
129
142
pytest .skip (f"{ driver_class } does not support BiDi" )
143
+
130
144
# conditionally mark tests as expected to fail based on driver
131
145
marker = request .node .get_closest_marker (f"xfail_{ driver_class .lower ()} " )
132
146
@@ -177,6 +191,7 @@ def fin():
177
191
kwargs ["options" ] = options
178
192
179
193
driver_instance = getattr (webdriver , driver_class )(** kwargs )
194
+
180
195
yield driver_instance
181
196
# Close the browser after BiDi tests. Those make event subscriptions
182
197
# and doesn't seems to be stable enough, causing the flakiness of the
@@ -217,7 +232,6 @@ def get_options(driver_class, config):
217
232
if headless :
218
233
if not options :
219
234
options = getattr (webdriver , f"{ driver_class } Options" )()
220
-
221
235
if driver_class == "Chrome" or driver_class == "Edge" :
222
236
options .add_argument ("--headless=new" )
223
237
if driver_class == "Firefox" :
@@ -226,7 +240,6 @@ def get_options(driver_class, config):
226
240
if bidi :
227
241
if not options :
228
242
options = getattr (webdriver , f"{ driver_class } Options" )()
229
-
230
243
options .web_socket_url = True
231
244
options .unhandled_prompt_behavior = "ignore"
232
245
@@ -382,3 +395,11 @@ def clean_driver(request):
382
395
383
396
if request .node .get_closest_marker ("no_driver_after_test" ):
384
397
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