Skip to content

[py] Use XWayland for internal Python Firefox tests #15601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 10, 2025
6 changes: 6 additions & 0 deletions py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def fin():
if driver_instance is None:
if driver_class == "Firefox":
options = get_options(driver_class, request.config)
# There are issues with window size/position when running Firefox
# under Wayland, so we use XWayland instead.
os.environ["MOZ_ENABLE_WAYLAND"] = "0"
if driver_class == "Chrome":
options = get_options(driver_class, request.config)
if driver_class == "Edge":
Expand All @@ -166,6 +169,9 @@ def fin():
options = get_options("Firefox", request.config) or webdriver.FirefoxOptions()
options.set_capability("moz:firefoxOptions", {})
options.enable_downloads = True
# There are issues with window size/position when running Firefox
# under Wayland, so we use XWayland instead.
os.environ["MOZ_ENABLE_WAYLAND"] = "0"
if driver_path is not None:
kwargs["service"] = get_service(driver_class, driver_path)
if options is not None:
Expand Down
62 changes: 62 additions & 0 deletions py/test/selenium/webdriver/firefox/firefox_sizing_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import os
import platform
from unittest.mock import patch

import pytest

from selenium import webdriver
from selenium.webdriver.firefox.options import Options


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


@pytest.mark.skipif(not is_running_wayland(), reason="This test only runs on Linux under Wayland")
def test_firefox_opens_large_when_running_xwayland(request): # noqa: F821
options = Options()
if request.config.getoption("--headless"):
options.add_argument("-headless")
# setting environment variable `MOZ_ENABLE_WAYLAND=0` forces Firefox
# to run under XWayland on Wayland based systems
with patch.dict("os.environ", {"MOZ_ENABLE_WAYLAND": "0"}):
try:
driver = webdriver.Firefox(options=options)
size = driver.get_window_size()
assert size["height"] > 500
assert size["width"] > 500
finally:
driver.quit()


@pytest.mark.skipif(not is_running_wayland(), reason="This test only runs on Linux under Wayland")
@pytest.mark.xfail(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1959040")
# Firefox opens in a small window when running on Linux/Wayland
def test_firefox_opens_large_when_running_wayland(request): # noqa: F821
options = Options()
if request.config.getoption("--headless"):
options.add_argument("-headless")
try:
driver = webdriver.Firefox(options=options)
size = driver.get_window_size()
assert size["height"] > 500
assert size["width"] > 500
finally:
driver.quit()
Loading