Skip to content

Commit b45919c

Browse files
Merge branch 'trunk' into refactor
2 parents 0de97c7 + 78ffa20 commit b45919c

File tree

9 files changed

+98
-41
lines changed

9 files changed

+98
-41
lines changed

py/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,16 @@ def options(self, cls_name):
229229
if cls_name.lower() not in self._supported_options:
230230
raise AttributeError(f"Invalid Options class {cls_name.lower()}")
231231
self._options = getattr(webdriver, getattr(self._supported_options, cls_name.lower()))()
232+
if self.driver_class == self._supported_drivers.firefox:
233+
# There are issues with window size/position when running Firefox
234+
# under Wayland, so we use XWayland instead.
235+
os.environ["MOZ_ENABLE_WAYLAND"] = "0"
232236
if self.driver_class == self._supported_drivers.remote:
233237
self._options.set_capability("moz:firefoxOptions", {})
234238
self._options.enable_downloads = True
239+
# There are issues with window size/position when running Firefox
240+
# under Wayland, so we use XWayland instead.
241+
os.environ["MOZ_ENABLE_WAYLAND"] = "0"
235242
if self.driver_class == self._supported_drivers.webkitgtk:
236243
self._options.overlay_scrollbars_enabled = False
237244

@@ -301,7 +308,7 @@ def driver(request):
301308

302309
if driver_instance is None:
303310
driver_instance = selenium_driver.driver
304-
311+
305312
yield driver_instance
306313

307314

py/test/selenium/webdriver/chrome/chrome_service_tests.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import subprocess
1919
import time
20+
from unittest.mock import patch
2021

2122
import pytest
2223

@@ -125,8 +126,6 @@ def test_uses_path_from_env_variable(self, service):
125126
assert "chromedriver" in service.path
126127

127128
def test_updates_path_after_setting_env_variable(self, service):
128-
new_path = "/foo/bar"
129-
os.environ["SE_CHROMEDRIVER"] = new_path
130129
service.executable_path = self.service_path # Simulating the update
131-
132-
assert "chromedriver" in service.executable_path
130+
with patch.dict("os.environ", {"SE_CHROMEDRIVER": "/foo/bar"}):
131+
assert "chromedriver" in service.executable_path

py/test/selenium/webdriver/chrome/proxy_tests.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import os
18+
from unittest.mock import patch
1919

2020
import pytest
2121
import urllib3
@@ -25,20 +25,15 @@
2525

2626
@pytest.mark.no_driver_after_test
2727
def test_bad_proxy_doesnt_interfere(clean_driver, clean_service):
28-
# these values should be ignored if ignore_local_proxy_environment_variables() is called.
29-
os.environ["https_proxy"] = "bad"
30-
os.environ["http_proxy"] = "bad"
28+
# Proxy environment variables should be ignored if
29+
# ignore_local_proxy_environment_variables() is called.
3130

3231
options = webdriver.ChromeOptions()
33-
3432
options.ignore_local_proxy_environment_variables()
35-
3633
chrome_kwargs = {"options": options, "service": clean_service}
37-
driver = clean_driver(**chrome_kwargs)
38-
34+
with patch.dict("os.environ", {"http_proxy": "bad", "https_proxy": "bad"}):
35+
driver = clean_driver(**chrome_kwargs)
3936
assert hasattr(driver, "command_executor")
4037
assert hasattr(driver.command_executor, "_proxy_url")
4138
assert isinstance(driver.command_executor._conn, urllib3.PoolManager)
42-
os.environ.pop("https_proxy")
43-
os.environ.pop("http_proxy")
4439
driver.quit()

py/test/selenium/webdriver/edge/edge_service_tests.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import subprocess
1919
import time
20+
from unittest.mock import patch
2021

2122
import pytest
2223

@@ -125,8 +126,6 @@ def test_uses_path_from_env_variable(self, service):
125126
assert "msedgedriver" in service.path
126127

127128
def test_updates_path_after_setting_env_variable(self, service):
128-
new_path = "/foo/bar"
129-
os.environ["SE_EDGEDRIVER"] = new_path
130129
service.executable_path = self.service_path # Simulating the update
131-
132-
assert "msedgedriver" in service.executable_path
130+
with patch.dict("os.environ", {"SE_EDGEDRIVER": "/foo/bar"}):
131+
assert "msedgedriver" in service.executable_path

py/test/selenium/webdriver/firefox/firefox_service_tests.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717
import os
1818
import subprocess
19+
from unittest.mock import patch
1920

2021
import pytest
2122

@@ -79,8 +80,6 @@ def test_uses_path_from_env_variable(self, service):
7980
assert "geckodriver" in service.path
8081

8182
def test_updates_path_after_setting_env_variable(self, service):
82-
new_path = "/foo/bar"
83-
os.environ["SE_GECKODRIVER"] = new_path
8483
service.executable_path = self.service_path # Simulating the update
85-
86-
assert "geckodriver" in service.executable_path
84+
with patch.dict("os.environ", {"SE_GECKODRIVER": "/foo/bar"}):
85+
assert "geckodriver" in service.executable_path
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
import os
19+
import platform
20+
from unittest.mock import patch
21+
22+
import pytest
23+
24+
from selenium import webdriver
25+
from selenium.webdriver.firefox.options import Options
26+
27+
28+
def is_running_wayland():
29+
return platform.system() == "Linux" and os.getenv("WAYLAND_DISPLAY")
30+
31+
32+
@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(request): # noqa: F821
34+
options = Options()
35+
if request.config.getoption("--headless"):
36+
options.add_argument("-headless")
37+
# setting environment variable `MOZ_ENABLE_WAYLAND=0` forces Firefox
38+
# to run under XWayland on Wayland based systems
39+
with patch.dict("os.environ", {"MOZ_ENABLE_WAYLAND": "0"}):
40+
try:
41+
driver = webdriver.Firefox(options=options)
42+
size = driver.get_window_size()
43+
assert size["height"] > 500
44+
assert size["width"] > 500
45+
finally:
46+
driver.quit()
47+
48+
49+
@pytest.mark.skipif(not is_running_wayland(), reason="This test only runs on Linux under Wayland")
50+
@pytest.mark.xfail(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1959040")
51+
# Firefox opens in a small window when running on Linux/Wayland
52+
def test_firefox_opens_large_when_running_wayland(request): # noqa: F821
53+
options = Options()
54+
if request.config.getoption("--headless"):
55+
options.add_argument("-headless")
56+
try:
57+
driver = webdriver.Firefox(options=options)
58+
size = driver.get_window_size()
59+
assert size["height"] > 500
60+
assert size["width"] > 500
61+
finally:
62+
driver.quit()

py/test/selenium/webdriver/safari/safari_service_tests.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717

1818
import os
19+
from unittest.mock import patch
1920

2021
import pytest
2122

@@ -41,11 +42,9 @@ def test_uses_path_from_env_variable(self, service):
4142
assert "safaridriver" in service.path
4243

4344
def test_updates_path_after_setting_env_variable(self, service):
44-
new_path = "/foo/bar"
45-
os.environ["SE_SAFARIDRIVER"] = new_path
4645
service.executable_path = self.service_path # Simulating the update
47-
48-
assert "safaridriver" in service.executable_path
46+
with patch.dict("os.environ", {"SE_SAFARIDRIVER": "/foo/bar"}):
47+
assert "safaridriver" in service.executable_path
4948

5049

5150
def test_enable_logging():

py/test/unit/selenium/webdriver/remote/remote_connection_tests.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import os
1918
from unittest.mock import patch
2019
from urllib import parse
2120

@@ -168,18 +167,17 @@ def test_get_proxy_direct_via_client_config():
168167

169168

170169
def test_get_proxy_system_matches_no_proxy_via_client_config():
171-
os.environ["HTTP_PROXY"] = "http://admin:admin@system_proxy.com:8080"
172-
os.environ["NO_PROXY"] = "localhost,127.0.0.1"
173-
client_config = ClientConfig(
174-
remote_server_addr="http://localhost:4444", proxy=Proxy({"proxyType": ProxyType.SYSTEM})
175-
)
176-
remote_connection = RemoteConnection(client_config=client_config)
177-
conn = remote_connection._get_connection_manager()
178-
assert isinstance(conn, urllib3.PoolManager)
179-
proxy_url = remote_connection._client_config.get_proxy_url()
180-
assert proxy_url is None
181-
os.environ.pop("HTTP_PROXY")
182-
os.environ.pop("NO_PROXY")
170+
with patch.dict(
171+
"os.environ", {"HTTP_PROXY": "http://admin:admin@system_proxy.com:8080", "NO_PROXY": "localhost,127.0.0.1"}
172+
):
173+
client_config = ClientConfig(
174+
remote_server_addr="http://localhost:4444", proxy=Proxy({"proxyType": ProxyType.SYSTEM})
175+
)
176+
remote_connection = RemoteConnection(client_config=client_config)
177+
conn = remote_connection._get_connection_manager()
178+
assert isinstance(conn, urllib3.PoolManager)
179+
proxy_url = remote_connection._client_config.get_proxy_url()
180+
assert proxy_url is None
183181

184182

185183
def test_get_proxy_url_none(mock_proxy_settings_missing):

rb/lib/selenium/webdriver/common/print_options.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919

20-
2120
module Selenium
2221
module WebDriver
2322
# Represents options for printing a page.

0 commit comments

Comments
 (0)