Skip to content

Commit cb4a6a8

Browse files
authored
Merge branch 'trunk' into migrate-caffeine
2 parents 174effe + 1a7edb2 commit cb4a6a8

16 files changed

+1366
-142
lines changed

py/BUILD.bazel

+1-2
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ py_library(
321321
"test/selenium/webdriver/__init__.py",
322322
"test/selenium/webdriver/chrome/__init__.py",
323323
"test/selenium/webdriver/common/__init__.py",
324-
"test/selenium/webdriver/common/conftest.py",
325324
"test/selenium/webdriver/common/network.py",
326325
"test/selenium/webdriver/common/webserver.py",
327326
"test/selenium/webdriver/firefox/__init__.py",
@@ -330,7 +329,6 @@ py_library(
330329
"test/selenium/webdriver/marionette/conftest.py",
331330
"test/selenium/webdriver/safari/conftest.py",
332331
"test/selenium/webdriver/support/__init__.py",
333-
"test/selenium/webdriver/support/conftest.py",
334332
],
335333
data = [
336334
"pyproject.toml",
@@ -547,6 +545,7 @@ py_test_suite(
547545
srcs = glob(
548546
[
549547
"test/selenium/webdriver/common/**/*.py",
548+
"test/selenium/webdriver/remote/**/*.py",
550549
"test/selenium/webdriver/support/**/*.py",
551550
],
552551
exclude = BIDI_TESTS,

py/conftest.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -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+
99104
def 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")
114119
def 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

Comments
 (0)