Skip to content

[py] Improve Selenium Manager platform/architecture detection#17271

Merged
cgoldberg merged 2 commits intoSeleniumHQ:trunkfrom
cgoldberg:py-selenium-manager-arch
Mar 29, 2026
Merged

[py] Improve Selenium Manager platform/architecture detection#17271
cgoldberg merged 2 commits intoSeleniumHQ:trunkfrom
cgoldberg:py-selenium-manager-arch

Conversation

@cgoldberg
Copy link
Copy Markdown
Member

💥 What does this PR do?

Supersedes: #17263

This PR improves platform/architecture detection for Selenium Manager.

On versions of Python older than 3.14. sys.platform on FreeBSD/OpenBSD includes the version number (i.e. freebsd15). This handles those cases by explicitly setting a normalized platform name. It also updates the warning about Selenium Manager binary on FreeBSD to hint at user what they need to do to get the Linux binary working on FreeBSD.

Also, some platforms return amd64 or AMD64 for architecture. This normalizes them to X86_64 so they are handled the same.

Previously, we were allowing "any" architecture on Windows, so the proper exception was not raised and Selenium Manager would fail to run instead.

This PR also adds unit tests for these.

🔄 Types of changes

  • Bug fix (backwards compatible)

@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Fix Selenium Manager platform and architecture detection

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fixes platform/architecture detection for Selenium Manager
• Normalizes amd64/AMD64 architecture to x86_64
• Handles BSD platform names with version numbers
• Restricts Windows to x86_64 architecture only
• Adds comprehensive unit tests for platform detection

Grey Divider

File Changes

1. py/selenium/webdriver/common/selenium_manager.py 🐞 Bug fix +19/-7

Improve platform and architecture detection logic

• Changed Windows platform to require x86_64 architecture instead of "any"
• Added normalization of amd64/AMD64 to x86_64 for consistent handling
• Added logic to strip version numbers from BSD platform names (freebsd15 → freebsd)
• Improved FreeBSD warning message with actionable instructions about brandelf and linux64.ko
• Refactored architecture detection to use lowercase normalization

py/selenium/webdriver/common/selenium_manager.py


2. py/test/unit/selenium/webdriver/common/selenium_manager_tests.py 🧪 Tests +24/-10

Add tests for platform and architecture detection

• Added import for logging module
• Added test_uses_windows_arm64 to verify ARM64 raises exception on Windows
• Added test_uses_freebsd to verify FreeBSD platform detection with amd64 normalization
• Verified warning message is logged for FreeBSD compatibility
• Cleaned up whitespace in existing tests

py/test/unit/selenium/webdriver/common/selenium_manager_tests.py


Grey Divider

Qodo Logo

@selenium-ci selenium-ci added the C-py Python Bindings label Mar 29, 2026
@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review bot commented Mar 29, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Windows test host-arch dependent🐞 Bug ⛯ Reliability
Description
test_uses_windows only monkeypatches sys.platform to win32; after this PR,
SeleniumManager._get_binary reads platform.machine() for Windows and only allows x86_64, so the test
can fail on ARM64/non-x86_64 runners by raising WebDriverException instead of returning the expected
path.
Code

py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[R53-57]

def test_uses_windows(monkeypatch):
    monkeypatch.setattr(sys, "platform", "win32")
    binary = SeleniumManager()._get_binary()
-
    project_root = Path(selenium.__file__).parent.parent
    assert binary == project_root.joinpath("selenium/webdriver/common/windows/selenium-manager.exe")
Evidence
_get_binary now derives arch from platform.machine().lower() for non-darwin platforms and only maps
Windows to the binary for (win32, x86_64). test_uses_windows sets sys.platform to win32 but does not
control platform.machine(), making the test outcome depend on the host CPU architecture (e.g., ARM64
runners will raise the unsupported-platform exception).

py/selenium/webdriver/common/selenium_manager.py[90-117]
py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[53-58]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`test_uses_windows` becomes architecture-dependent because `_get_binary()` now calls `platform.machine()` on Windows and only supports `x86_64`, but the test does not monkeypatch `platform.machine()`.

### Issue Context
On ARM64/non-x86_64 CI runners, `platform.machine()` will not be `amd64/AMD64/x86_64`, causing `_get_binary()` to raise and the test to fail.

### Fix Focus Areas
- py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[53-58]

### Suggested change
In `test_uses_windows`, add `monkeypatch.setattr("platform.machine", lambda: "AMD64")` (or `"x86_64"`) before calling `_get_binary()` so the test is deterministic across CI architectures.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@cgoldberg cgoldberg changed the title [py] Improves Selenium Manager platform/architecture detection [py] Improve Selenium Manager platform/architecture detection Mar 29, 2026
@cgoldberg
Copy link
Copy Markdown
Member Author

The RBE failures are unrelated.. all python tests pass

@cgoldberg cgoldberg merged commit 16c046a into SeleniumHQ:trunk Mar 29, 2026
28 of 29 checks passed
@cgoldberg cgoldberg deleted the py-selenium-manager-arch branch March 29, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants