Skip to content

[py] WIP - Support ARM binary selection for Selenium Manager #16052

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

Draft
wants to merge 9 commits into
base: trunk
Choose a base branch
from
Draft
12 changes: 12 additions & 0 deletions py/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,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",
Expand All @@ -112,6 +118,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",
Expand Down
2 changes: 2 additions & 0 deletions py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ target = "selenium.webdriver.common.selenium-manager"
"prune*",
"selenium.egg-info*",
"selenium-manager",
"selenium-manager-arm64",
"selenium-manager.exe",
"selenium-manager-arm64.exe",
"CHANGES",
"LICENSE"
]
Expand Down
22 changes: 19 additions & 3 deletions py/selenium/webdriver/common/selenium_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import json
import logging
import os
Expand Down Expand Up @@ -77,14 +78,29 @@ def _get_binary() -> Path:
else:
allowed = {
("darwin", "any"): "macos/selenium-manager",
("win32", "any"): "windows/selenium-manager.exe",
("cygwin", "any"): "windows/selenium-manager.exe",
("win32", "amd64"): "windows/selenium-manager.exe",
("win32", "x86_64"): "windows/selenium-manager.exe",
("win32", "arm64"): "windows/selenium-manager-arm64.exe",
("win32", "aarch64"): "windows/selenium-manager-arm64.exe",
("cygwin", "amd64"): "windows/selenium-manager.exe",
("cygwin", "x86_64"): "windows/selenium-manager.exe",
("cygwin", "arm64"): "windows/selenium-manager-arm64.exe",
("cygwin", "aarch64"): "windows/selenium-manager-arm64.exe",
("linux", "amd64"): "linux/selenium-manager",
("linux", "x86_64"): "linux/selenium-manager",
("linux", "arm64"): "linux/selenium-manager-arm64",
("linux", "aarch64"): "linux/selenium-manager-arm64",
("freebsd", "amd64"): "linux/selenium-manager",
("freebsd", "x86_64"): "linux/selenium-manager",
("freebsd", "arm64"): "linux/selenium-manager-arm64",
("freebsd", "aarch64"): "linux/selenium-manager-arm64",
("openbsd", "amd64"): "linux/selenium-manager",
("openbsd", "x86_64"): "linux/selenium-manager",
("openbsd", "arm64"): "linux/selenium-manager-arm64",
("openbsd", "aarch64"): "linux/selenium-manager-arm64",
}

arch = platform.machine() if sys.platform in ("linux", "freebsd", "openbsd") else "any"
arch = "any" if sys.platform == "darwin" else platform.machine().lower()
if sys.platform in ["freebsd", "openbsd"]:
logger.warning("Selenium Manager binary may not be compatible with %s; verify settings", sys.platform)

Expand Down
32 changes: 24 additions & 8 deletions py/test/selenium/webdriver/common/selenium_manager_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import json
import platform
import sys
from pathlib import Path
from unittest import mock
Expand Down Expand Up @@ -53,22 +53,38 @@ 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")

if platform.machine() == "arm64":
with pytest.raises(WebDriverException, match="Unsupported platform/architecture combination: linux/arm64"):
SeleniumManager()._get_binary()
else:
binary = SeleniumManager()._get_binary()
project_root = Path(selenium.__file__).parent.parent
assert binary == project_root.joinpath("selenium/webdriver/common/linux/selenium-manager")
binary = SeleniumManager()._get_binary()
project_root = Path(selenium.__file__).parent.parent
assert binary == project_root.joinpath("selenium/webdriver/common/linux/selenium-manager")


def test_uses_linux_arm(monkeypatch):
monkeypatch.setattr(sys, "platform", "linux")
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/linux/selenium-manager-arm64")


def test_uses_mac(monkeypatch):
Expand Down
Loading