diff --git a/py/conftest.py b/py/conftest.py index c790b27a489c0..37f76fb1731b4 100644 --- a/py/conftest.py +++ b/py/conftest.py @@ -16,7 +16,7 @@ # under the License. import os -import platform +import sys from dataclasses import dataclass from pathlib import Path @@ -182,7 +182,14 @@ def driver_class(self, cls_name): @property def exe_platform(self): - return platform.system() + if sys.platform == "win32": + return "Windows" + elif sys.platform == "darwin": + return "Darwin" + elif sys.platform == "linux": + return "Linux" + else: + return sys.platform.title() @property def browser_path(self): @@ -397,7 +404,7 @@ def server(request): ) remote_env = os.environ.copy() - if platform.system() == "Linux": + if sys.platform == "linux": # There are issues with window size/position when running Firefox # under Wayland, so we use XWayland instead. remote_env["MOZ_ENABLE_WAYLAND"] = "0" diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index 7b3bdf81c403a..d8e7ac018df87 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -19,10 +19,10 @@ import logging import os import subprocess +import sys from abc import ABC, abstractmethod from collections.abc import Mapping from io import IOBase -from platform import system from subprocess import PIPE from time import sleep from typing import IO, Any, Optional, Union, cast @@ -205,13 +205,13 @@ def _start_process(self, path: str) -> None: """ cmd = [path] cmd.extend(self.command_line_args()) - close_file_descriptors = self.popen_kw.pop("close_fds", system() != "Windows") + close_file_descriptors = self.popen_kw.pop("close_fds", sys.platform != "win32") try: start_info = None - if system() == "Windows": - start_info = subprocess.STARTUPINFO() # type: ignore[attr-defined] - start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW # type: ignore[attr-defined] - start_info.wShowWindow = subprocess.SW_HIDE # type: ignore[attr-defined] + if sys.platform == "win32": + start_info = subprocess.STARTUPINFO() + start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW + start_info.wShowWindow = subprocess.SW_HIDE self.process = subprocess.Popen( cmd, diff --git a/py/selenium/webdriver/firefox/firefox_binary.py b/py/selenium/webdriver/firefox/firefox_binary.py index 6490c1f9db621..0932fa11e4176 100644 --- a/py/selenium/webdriver/firefox/firefox_binary.py +++ b/py/selenium/webdriver/firefox/firefox_binary.py @@ -17,8 +17,8 @@ import os +import sys import time -from platform import system from subprocess import DEVNULL, STDOUT, Popen from typing_extensions import deprecated @@ -45,7 +45,7 @@ def __init__(self, firefox_path=None, log_file=None): # a while the pipe would fill up and Firefox would freeze. self._log_file = log_file or DEVNULL self.command_line = None - self.platform = system().lower() + self.platform = sys.platform if not self._start_cmd: self._start_cmd = self._get_firefox_start_cmd() if not self._start_cmd.strip(): diff --git a/py/selenium/webdriver/remote/remote_connection.py b/py/selenium/webdriver/remote/remote_connection.py index 031481c68432b..2b496e42c7cb3 100644 --- a/py/selenium/webdriver/remote/remote_connection.py +++ b/py/selenium/webdriver/remote/remote_connection.py @@ -16,8 +16,8 @@ # under the License. import logging -import platform import string +import sys import warnings from base64 import b64encode from typing import Optional @@ -156,7 +156,7 @@ class RemoteConnection: _ca_certs = os.getenv("REQUESTS_CA_BUNDLE") if "REQUESTS_CA_BUNDLE" in os.environ else certifi.where() _client_config: Optional[ClientConfig] = None - system = platform.system().lower() + system = sys.platform if system == "darwin": system = "mac" diff --git a/py/test/selenium/webdriver/firefox/firefox_sizing_tests.py b/py/test/selenium/webdriver/firefox/firefox_sizing_tests.py index ce157bd7edfb2..eade45f0b01f4 100644 --- a/py/test/selenium/webdriver/firefox/firefox_sizing_tests.py +++ b/py/test/selenium/webdriver/firefox/firefox_sizing_tests.py @@ -16,7 +16,7 @@ # under the License. import os -import platform +import sys from unittest.mock import patch import pytest @@ -25,7 +25,7 @@ def is_running_wayland(): - return platform.system() == "Linux" and os.getenv("WAYLAND_DISPLAY") + return sys.platform == "linux" and os.getenv("WAYLAND_DISPLAY") @pytest.mark.skipif(not is_running_wayland(), reason="This test only runs on Linux under Wayland") diff --git a/py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py b/py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py index 107a31ea49c39..2102f5127e1d9 100644 --- a/py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py +++ b/py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py @@ -14,7 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import platform +import sys from os import path import pytest @@ -91,7 +91,7 @@ def test_add_encoded_extension(options): def test_get_extensions_from_extension_files(options, mocker): - null = "NUL" if platform.system().lower() == "windows" else "/dev/null" + null = "NUL" if sys.platform == "win32" else "/dev/null" mocker.patch("selenium.webdriver.chromium.options.open").return_value = open(null) mocker.patch("base64.b64encode").return_value = b"foo" options._extension_files = ["foo"]