@@ -97,6 +97,17 @@ def pytest_ignore_collect(path, config):
97
97
return len ([d for d in _drivers if d .lower () in parts ]) > 0
98
98
99
99
100
+ def get_driver_class (driver_option ):
101
+ """Generate the driver class name from the lowercase driver option"""
102
+ if driver_option == "webkitgtk" :
103
+ driver_class = "WebKitGTK"
104
+ elif driver_option == "wpewebkit" :
105
+ driver_class = "WPEWebKit"
106
+ else :
107
+ driver_class = driver_option .capitalize ()
108
+ return driver_class
109
+
110
+
100
111
driver_instance = None
101
112
102
113
@@ -105,7 +116,7 @@ def driver(request):
105
116
kwargs = {}
106
117
107
118
# browser can be changed with `--driver=firefox` as an argument or to addopts in pytest.ini
108
- driver_class = getattr (request , "param" , "Chrome" ). capitalize ( )
119
+ driver_class = get_driver_class ( getattr (request , "param" , "Chrome" ))
109
120
110
121
# skip tests if not available on the platform
111
122
_platform = platform .system ()
@@ -146,18 +157,16 @@ def fin():
146
157
options = get_options (driver_class , request .config )
147
158
if driver_class == "Chrome" :
148
159
options = get_options (driver_class , request .config )
160
+ if driver_class == "Edge" :
161
+ options = get_options (driver_class , request .config )
162
+ if driver_class == "WebKitGTK" :
163
+ options = get_options (driver_class , request .config )
164
+ if driver_class .lower () == "WPEWebKit" :
165
+ options = get_options (driver_class , request .config )
149
166
if driver_class == "Remote" :
150
167
options = get_options ("Firefox" , request .config ) or webdriver .FirefoxOptions ()
151
168
options .set_capability ("moz:firefoxOptions" , {})
152
169
options .enable_downloads = True
153
- if driver_class .lower () == "webkitgtk" :
154
- driver_class = "WebKitGTK"
155
- options = get_options (driver_class , request .config )
156
- if driver_class == "Edge" :
157
- options = get_options (driver_class , request .config )
158
- if driver_class .lower () == "wpewebkit" :
159
- driver_class = "WPEWebKit"
160
- options = get_options (driver_class , request .config )
161
170
if driver_path is not None :
162
171
kwargs ["service" ] = get_service (driver_class , driver_path )
163
172
if options is not None :
@@ -345,19 +354,19 @@ def driver_executable(request):
345
354
@pytest .fixture (scope = "function" )
346
355
def clean_service (request ):
347
356
try :
348
- driver_class = request .config .option .drivers [0 ]. capitalize ( )
349
- except AttributeError :
350
- raise Exception ("This test requires a --driver to be specified. " )
357
+ driver_class = get_driver_class ( request .config .option .drivers [0 ])
358
+ except ( AttributeError , TypeError ) :
359
+ raise Exception ("This test requires a --driver to be specified" )
351
360
352
361
yield get_service (driver_class , request .config .option .executable )
353
362
354
363
355
364
@pytest .fixture (scope = "function" )
356
365
def clean_driver (request ):
357
366
try :
358
- driver_class = request .config .option .drivers [0 ]. capitalize ( )
359
- except AttributeError :
360
- raise Exception ("This test requires a --driver to be specified. " )
367
+ driver_class = get_driver_class ( request .config .option .drivers [0 ])
368
+ except ( AttributeError , TypeError ) :
369
+ raise Exception ("This test requires a --driver to be specified" )
361
370
362
371
driver_reference = getattr (webdriver , driver_class )
363
372
yield driver_reference
0 commit comments