3737 "edge" ,
3838 "firefox" ,
3939 "ie" ,
40- "remote" ,
4140 "safari" ,
4241 "webkitgtk" ,
4342 "wpewebkit" ,
@@ -89,6 +88,12 @@ def pytest_addoption(parser):
8988 dest = "bidi" ,
9089 help = "Enable BiDi support" ,
9190 )
91+ parser .addoption (
92+ "--remote" ,
93+ action = "store_true" ,
94+ dest = "remote" ,
95+ help = "Run tests against a remote Grid server" ,
96+ )
9297
9398
9499def pytest_ignore_collect (collection_path , config ):
@@ -125,7 +130,6 @@ class SupportedDrivers(ContainerProtocol):
125130 ie : str = "Ie"
126131 webkitgtk : str = "WebKitGTK"
127132 wpewebkit : str = "WPEWebKit"
128- remote : str = "Remote"
129133
130134
131135@dataclass
@@ -135,7 +139,6 @@ class SupportedOptions(ContainerProtocol):
135139 edge : str = "EdgeOptions"
136140 safari : str = "SafariOptions"
137141 ie : str = "IeOptions"
138- remote : str = "ChromeOptions"
139142 webkitgtk : str = "WebKitGTKOptions"
140143 wpewebkit : str = "WPEWebKitOptions"
141144
@@ -145,7 +148,6 @@ class SupportedBidiDrivers(ContainerProtocol):
145148 chrome : str = "Chrome"
146149 firefox : str = "Firefox"
147150 edge : str = "Edge"
148- remote : str = "Remote"
149151
150152
151153class Driver :
@@ -252,10 +254,6 @@ def options(self, cls_name):
252254 # There are issues with window size/position when running Firefox
253255 # under Wayland, so we use XWayland instead.
254256 os .environ ["MOZ_ENABLE_WAYLAND" ] = "0"
255- elif self .driver_class == self .supported_drivers .remote :
256- self ._options = getattr (webdriver , self .supported_options .chrome )()
257- self ._options .set_capability ("goog:chromeOptions" , {})
258- self ._options .enable_downloads = True
259257 else :
260258 opts_cls = getattr (self .supported_options , cls_name .lower ())
261259 self ._options = getattr (webdriver , opts_cls )()
@@ -297,10 +295,17 @@ def is_platform_valid(self):
297295 return False
298296 return True
299297
298+ @property
299+ def is_remote (self ):
300+ return self ._request .config .getoption ("remote" )
301+
300302 def _initialize_driver (self ):
301303 kwargs = {}
302304 if self .options is not None :
303305 kwargs ["options" ] = self .options
306+ if self .is_remote :
307+ # Use Remote driver with the specified browser's options
308+ return webdriver .Remote (** kwargs )
304309 if self .driver_path is not None :
305310 kwargs ["service" ] = self .service
306311 return getattr (webdriver , self .driver_class )(** kwargs )
@@ -324,9 +329,9 @@ def driver(request):
324329 if not selenium_driver .is_platform_valid :
325330 pytest .skip (f"{ driver_class } tests can only run on { selenium_driver .exe_platform } " )
326331
327- # skip tests in the 'remote' directory if run with a local driver
328- if request .node .path .parts [- 2 ] == "remote" and selenium_driver .driver_class != "Remote" :
329- pytest .skip (f "Remote tests can't be run with driver ' { selenium_driver . driver_class } ' " )
332+ # skip tests in the 'remote' directory if not running with --remote flag
333+ if request .node .path .parts [- 2 ] == "remote" and not selenium_driver .is_remote :
334+ pytest .skip ("Remote tests require the --remote flag " )
330335
331336 # skip tests for drivers that don't support BiDi when --bidi is enabled
332337 if selenium_driver .bidi :
@@ -416,8 +421,8 @@ def load(self, name):
416421
417422@pytest .fixture (autouse = True , scope = "session" )
418423def server (request ):
419- drivers = request .config .getoption ("drivers " )
420- if drivers is None or "remote" not in drivers :
424+ is_remote = request .config .getoption ("remote " )
425+ if not is_remote :
421426 yield None
422427 return
423428
@@ -507,19 +512,19 @@ def clean_options(request):
507512
508513@pytest .fixture
509514def firefox_options (request ):
510- _supported_drivers = SupportedDrivers ()
511515 try :
512516 driver_class = request .config .option .drivers [0 ].lower ()
513517 except (AttributeError , TypeError ):
514518 raise Exception ("This test requires a --driver to be specified" )
515519
516- # skip if not Firefox or Remote
517- if driver_class not in ( "firefox" , "remote" ) :
518- pytest .skip (f"This test requires Firefox or Remote . Got { driver_class } " )
520+ # skip if not Firefox
521+ if driver_class != "firefox" :
522+ pytest .skip (f"This test requires Firefox. Got { driver_class } " )
519523
520- # skip tests in the 'remote' directory if run with a local driver
521- if request .node .path .parts [- 2 ] == "remote" and getattr (_supported_drivers , driver_class ) != "Remote" :
522- pytest .skip (f"Remote tests can't be run with driver '{ driver_class } '" )
524+ # skip tests in the 'remote' directory if not running with --remote flag
525+ is_remote = request .config .getoption ("remote" )
526+ if request .node .path .parts [- 2 ] == "remote" and not is_remote :
527+ pytest .skip ("Remote tests require the --remote flag" )
523528
524529 options = Driver .clean_options ("firefox" , request )
525530
@@ -528,24 +533,21 @@ def firefox_options(request):
528533
529534@pytest .fixture
530535def chromium_options (request ):
531- _supported_drivers = SupportedDrivers ()
532536 try :
533537 driver_class = request .config .option .drivers [0 ].lower ()
534538 except (AttributeError , TypeError ):
535539 raise Exception ("This test requires a --driver to be specified" )
536540
537- # skip if not Chrome, Edge, or Remote
538- if driver_class not in ("chrome" , "edge" , "remote" ):
539- pytest .skip (f"This test requires Chrome, Edge, or Remote . Got { driver_class } " )
541+ # skip if not Chrome or Edge
542+ if driver_class not in ("chrome" , "edge" ):
543+ pytest .skip (f"This test requires Chrome or Edge . Got { driver_class } " )
540544
541- # skip tests in the 'remote' directory if run with a local driver
542- if request .node .path .parts [- 2 ] == "remote" and getattr (_supported_drivers , driver_class ) != "Remote" :
543- pytest .skip (f"Remote tests can't be run with driver '{ driver_class } '" )
545+ # skip tests in the 'remote' directory if not running with --remote flag
546+ is_remote = request .config .getoption ("remote" )
547+ if request .node .path .parts [- 2 ] == "remote" and not is_remote :
548+ pytest .skip ("Remote tests require the --remote flag" )
544549
545- if driver_class in ("chrome" , "remote" ):
546- options = Driver .clean_options ("chrome" , request )
547- else :
548- options = Driver .clean_options ("edge" , request )
550+ options = Driver .clean_options (driver_class , request )
549551
550552 return options
551553
0 commit comments