Skip to content

Commit 774d4c3

Browse files
committed
[py] Move headless option to fixture
1 parent 374c20b commit 774d4c3

File tree

4 files changed

+16
-30
lines changed

4 files changed

+16
-30
lines changed

py/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,5 +398,8 @@ def clean_driver(request):
398398

399399

400400
@pytest.fixture
401-
def headless(request):
402-
return request.config.option.headless
401+
def firefox_options(request):
402+
options = webdriver.FirefoxOptions()
403+
if request.config.option.headless:
404+
options.add_argument("-headless")
405+
return options

py/test/selenium/webdriver/firefox/firefox_sizing_tests.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,27 @@
2222
import pytest
2323

2424
from selenium import webdriver
25-
from selenium.webdriver.firefox.options import Options
2625

2726

2827
def is_running_wayland():
2928
return platform.system() == "Linux" and os.getenv("WAYLAND_DISPLAY")
3029

3130

3231
@pytest.mark.skipif(not is_running_wayland(), reason="This test only runs on Linux under Wayland")
33-
def test_firefox_opens_large_when_running_xwayland(headless):
32+
def test_firefox_opens_large_when_running_xwayland(firefox_options):
3433
# setting environment variable `MOZ_ENABLE_WAYLAND=0` forces Firefox
3534
# to run under XWayland on Wayland based systems
3635
with patch.dict("os.environ", {"MOZ_ENABLE_WAYLAND": "0"}):
37-
options = Options()
38-
if headless:
39-
options.add_argument("-headless")
40-
with webdriver.Firefox(options=options) as driver:
36+
with webdriver.Firefox(options=firefox_options) as driver:
4137
size = driver.get_window_size()
4238
assert size["height"] > 500
4339
assert size["width"] > 500
4440

4541

4642
@pytest.mark.skipif(not is_running_wayland(), reason="This test only runs on Linux under Wayland")
4743
@pytest.mark.xfail(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1959040")
48-
def test_firefox_opens_large_when_running_wayland(headless):
49-
options = Options()
50-
if headless:
51-
options.add_argument("-headless")
52-
with webdriver.Firefox(options=options) as driver:
44+
def test_firefox_opens_large_when_running_wayland(firefox_options):
45+
with webdriver.Firefox(options=firefox_options) as driver:
5346
size = driver.get_window_size()
5447
assert size["height"] > 500
5548
assert size["width"] > 500

py/test/selenium/webdriver/remote/remote_custom_locator_tests.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import pytest
1919

2020
from selenium import webdriver
21-
from selenium.webdriver.firefox.options import Options
2221
from selenium.webdriver.remote.locator_converter import LocatorConverter
2322

2423

@@ -31,15 +30,10 @@ def convert(self, by, value):
3130

3231

3332
@pytest.fixture()
34-
def custom_locator_driver(headless):
35-
options = Options()
36-
if headless:
37-
options.add_argument("-headless")
38-
try:
39-
driver = webdriver.Remote(options=options, locator_converter=CustomLocatorConverter())
40-
yield driver
41-
finally:
42-
driver.quit()
33+
def custom_locator_driver(firefox_options):
34+
driver = webdriver.Remote(options=firefox_options, locator_converter=CustomLocatorConverter())
35+
yield driver
36+
driver.quit()
4337

4438

4539
def test_find_element_with_custom_locator(custom_locator_driver):

py/test/selenium/webdriver/remote/remote_firefox_profile_tests.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@
1717

1818
from selenium import webdriver
1919
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
20-
from selenium.webdriver.firefox.options import Options
2120

2221

23-
def test_profile_is_used(headless):
22+
def test_profile_is_used(firefox_options):
2423
ff_profile = FirefoxProfile()
2524
ff_profile.set_preference("browser.startup.page", "1")
26-
options = Options()
27-
options.profile = ff_profile
28-
if headless:
29-
options.add_argument("-headless")
30-
with webdriver.Remote(options=options) as driver:
25+
firefox_options.profile = ff_profile
26+
with webdriver.Remote(options=firefox_options) as driver:
3127
assert "browser/content/blanktab.html" in driver.current_url

0 commit comments

Comments
 (0)