Skip to content

Commit 332979c

Browse files
committed
support remote independently of browser
1 parent 3a20b47 commit 332979c

File tree

2 files changed

+70
-58
lines changed

2 files changed

+70
-58
lines changed

py/BUILD.bazel

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -511,34 +511,44 @@ BROWSER_TESTS = {
511511
if BROWSER_TESTS[browser].get("bidi", False)
512512
]
513513

514-
py_test_suite(
515-
name = "test-remote",
516-
size = "large",
517-
srcs = glob(
518-
[
519-
"test/selenium/webdriver/common/**/*.py",
520-
"test/selenium/webdriver/remote/**/*.py",
521-
"test/selenium/webdriver/support/**/*.py",
514+
# Generate test-<browser>-remote targets (chrome and firefox only)
515+
[
516+
py_test_suite(
517+
name = "test-%s-remote" % browser,
518+
size = "large",
519+
srcs = glob(
520+
[
521+
"test/selenium/webdriver/common/**/*.py",
522+
"test/selenium/webdriver/remote/**/*.py",
523+
"test/selenium/webdriver/support/**/*.py",
524+
] + BROWSER_TESTS[browser]["browser_srcs"],
525+
exclude = BIDI_TESTS + ["test/selenium/webdriver/common/print_pdf_tests.py"] +
526+
BROWSER_TESTS[browser].get("extra_excludes", []),
527+
),
528+
args = [
529+
"--instafail",
530+
"--remote",
531+
] + BROWSERS[browser]["args"],
532+
data = BROWSERS[browser]["data"] + [
533+
"//java/src/org/openqa/selenium/grid:selenium_server_deploy.jar",
522534
],
523-
exclude = BIDI_TESTS,
524-
),
525-
args = [
526-
"--instafail",
527-
"--driver=remote",
528-
],
529-
data = [
530-
"//java/src/org/openqa/selenium/grid:selenium_server_deploy.jar",
531-
],
532-
tags = [
533-
"no-sandbox",
534-
"skip-rbe",
535-
],
536-
deps = [
537-
":init-tree",
538-
":selenium",
539-
":webserver",
540-
] + TEST_DEPS,
541-
)
535+
env_inherit = ["DISPLAY"],
536+
tags = [
537+
"no-sandbox",
538+
"%s-remote" % browser,
539+
"skip-rbe",
540+
],
541+
deps = [
542+
":init-tree",
543+
":selenium",
544+
":webserver",
545+
] + TEST_DEPS,
546+
)
547+
for browser in [
548+
"chrome",
549+
"firefox",
550+
]
551+
]
542552

543553
py_test_suite(
544554
name = "test-webkitgtk",

py/conftest.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
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

9499
def 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

151153
class 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")
418423
def 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
509514
def 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
530535
def 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

Comments
 (0)