diff --git a/py/BUILD.bazel b/py/BUILD.bazel index a0316f598548b..3b79fe977f512 100644 --- a/py/BUILD.bazel +++ b/py/BUILD.bazel @@ -87,6 +87,12 @@ copy_file( out = "selenium/webdriver/common/linux/selenium-manager", ) +copy_file( + name = "manager-linux-arm64", + src = "//common/manager:selenium-manager-linux-arm64", + out = "selenium/webdriver/common/linux/selenium-manager-arm64", +) + copy_file( name = "manager-macos", src = "//common/manager:selenium-manager-macos", @@ -99,6 +105,12 @@ copy_file( out = "selenium/webdriver/common/windows/selenium-manager.exe", ) +copy_file( + name = "manager-windows-arm64", + src = "//common/manager:selenium-manager-windows-arm64", + out = "selenium/webdriver/common/windows/selenium-manager-arm64.exe", +) + copy_file( name = "get-attribute", src = "//javascript/webdriver/atoms:get-attribute.js", diff --git a/py/pyproject.toml b/py/pyproject.toml index 6c68bba979a9e..541ea0a5e9e16 100644 --- a/py/pyproject.toml +++ b/py/pyproject.toml @@ -82,7 +82,9 @@ binding = "Exec" "prune*", "selenium.egg-info*", "selenium-manager", + "selenium-manager-arm64", "selenium-manager.exe", + "selenium-manager-arm64.exe", "CHANGES", "LICENSE", "NOTICE", diff --git a/py/selenium/webdriver/common/selenium_manager.py b/py/selenium/webdriver/common/selenium_manager.py index a4a8edd5366fe..95dd369b36e09 100644 --- a/py/selenium/webdriver/common/selenium_manager.py +++ b/py/selenium/webdriver/common/selenium_manager.py @@ -62,7 +62,13 @@ def _get_binary() -> Path: 1. location set in an environment variable 2. location where setuptools-rust places the compiled binary (built from the sdist package) - 3. location where we ship binaries in the wheel package for the platform this is running on + 3. location where we ship binaries in the wheel package for each platform and architecture + - `linux/selenium-manager` + - `linux/selenium-manager-arm64` + - `macos/selenium-manager` + - `macos/selenium-manager-arm64` + - `windows/selenium-manager.exe` + - `windows/selenium-manager-arm64.exe` 4. give up Returns: @@ -87,22 +93,27 @@ def _get_binary() -> Path: elif compiled_path.is_file(): path = compiled_path else: - allowed = { - ("darwin", "any"): "macos/selenium-manager", - ("win32", "any"): "windows/selenium-manager.exe", - ("cygwin", "any"): "windows/selenium-manager.exe", - ("linux", "x86_64"): "linux/selenium-manager", - ("freebsd", "x86_64"): "linux/selenium-manager", - ("openbsd", "x86_64"): "linux/selenium-manager", - } - - arch = platform.machine() if sys.platform in ("linux", "freebsd", "openbsd") else "any" - if sys.platform in ["freebsd", "openbsd"]: + is_windows = any(("win" in sys.platform, "cygwin" in sys.platform)) + + # choose the binary name for the architecture and platform/os + bin_name = "selenium-manager" + if platform.machine() in ("aarch64", "arm64"): + bin_name = f"{bin_name}-arm64" + if is_windows: + bin_name = f"{bin_name}.exe" + + # choose the directory of the binary for the platform/os + if is_windows: + location = f"windows/{bin_name}" + elif sys.platform == "darwin": + location = f"macos/{bin_name}" + elif sys.platform == "linux": + location = f"linux/{bin_name}" + elif "bsd" in sys.platform: + location = f"linux/{bin_name}" logger.warning(f"Selenium Manager binary may not be compatible with {sys.platform}; verify settings") - - location = allowed.get((sys.platform, arch)) - if location is None: - raise WebDriverException(f"Unsupported platform/architecture combination: {sys.platform}/{arch}") + else: + raise WebDriverException(f"Unsupported platform: {sys.platform}") path = Path(__file__).parent.joinpath(location) diff --git a/py/test/selenium/webdriver/common/selenium_manager_tests.py b/py/test/selenium/webdriver/common/selenium_manager_tests.py index 13edd5577ce7f..4b14e8e5bc00c 100644 --- a/py/test/selenium/webdriver/common/selenium_manager_tests.py +++ b/py/test/selenium/webdriver/common/selenium_manager_tests.py @@ -54,12 +54,22 @@ def test_uses_environment_variable(monkeypatch): def test_uses_windows(monkeypatch): monkeypatch.setattr(sys, "platform", "win32") + monkeypatch.setattr("platform.machine", lambda: "AMD64") binary = SeleniumManager()._get_binary() project_root = Path(selenium.__file__).parent.parent assert binary == project_root.joinpath("selenium/webdriver/common/windows/selenium-manager.exe") +def test_uses_windows_arm(monkeypatch): + monkeypatch.setattr(sys, "platform", "win32") + monkeypatch.setattr("platform.machine", lambda: "arm64") + binary = SeleniumManager()._get_binary() + + project_root = Path(selenium.__file__).parent.parent + assert binary == project_root.joinpath("selenium/webdriver/common/windows/selenium-manager-arm64.exe") + + def test_uses_linux(monkeypatch): monkeypatch.setattr(sys, "platform", "linux") monkeypatch.setattr("platform.machine", lambda: "x86_64") @@ -69,12 +79,13 @@ def test_uses_linux(monkeypatch): assert binary == project_root.joinpath("selenium/webdriver/common/linux/selenium-manager") -def test_uses_linux_arm64(monkeypatch): +def test_uses_linux_arm(monkeypatch): monkeypatch.setattr(sys, "platform", "linux") monkeypatch.setattr("platform.machine", lambda: "arm64") - with pytest.raises(WebDriverException, match="Unsupported platform/architecture combination: linux/arm64"): - SeleniumManager()._get_binary() + binary = SeleniumManager()._get_binary() + project_root = Path(selenium.__file__).parent.parent + assert binary == project_root.joinpath("selenium/webdriver/common/linux/selenium-manager-arm64") def test_uses_mac(monkeypatch): @@ -99,7 +110,7 @@ def test_errors_if_invalid_os(monkeypatch): with pytest.raises(WebDriverException) as excinfo: SeleniumManager()._get_binary() - assert "Unsupported platform/architecture combination" in str(excinfo.value) + assert "Unsupported platform" in str(excinfo.value) def test_error_if_invalid_env_path(monkeypatch):