Skip to content

[py][bidi]: add BiDi tests for userAgentClientHints - #18063

Open
aayushisabharwal wants to merge 6 commits into
SeleniumHQ:trunkfrom
aayushisabharwal:py-bidi-ua-client-hints-tests
Open

aayushisabharwal wants to merge 6 commits into
SeleniumHQ:trunkfrom
aayushisabharwal:py-bidi-ua-client-hints-tests

Conversation

@aayushisabharwal

Copy link
Copy Markdown
Contributor

🔗 Related Issues

None. This adds missing test coverage. Ruby already has the equivalent spec in rb/spec/integration/selenium/webdriver/bidi/protocol/user_agent_client_hints_spec.rb.

💥 What does this PR do?

The Python binding had no tests for userAgentClientHints.setClientHintsOverride. This adds py/test/selenium/webdriver/common/_bidi/user_agent_client_hints_tests.py with three tests:

  • test_set_client_hints_override_with_contexts: sets the override for the current browsing context, navigates, and asserts that navigator.userAgentData reports the overridden platform, brands and mobile values.
  • test_clear_client_hints_override: asserts the override is applied, then that passing None restores the browser's original platform.
  • test_set_client_hints_override_with_user_contexts: sets the override for a new user context and asserts that a tab opened in it sees the overridden platform.

🔧 Implementation Notes

  • Follows the existing user agent override tests in _bidi/emulation_tests.py (per context, per user context, reset) and mirrors the Ruby spec.
  • Each override is cleared in a finally block, or discarded together with its user context, so it cannot leak into other tests that share the BiDi session.
  • The tests cover Selenium's side of the command: parameter serialization, contexts / userContexts scoping, and sending null to clear. Browser conformance details such as scope precedence, high-entropy values and Sec-CH-UA* headers are left to web-platform-tests.
  • Marked xfail_firefox because Firefox does not implement the userAgentClientHints module. The Ruby spec is pending on Firefox for the same reason.

Verified locally on current trunk:

  • bazel test //py:test/selenium/webdriver/common/_bidi/user_agent_client_hints_tests-{chrome,edge,firefox}-bidi --cache_test_results=no: 3 passed on Chrome and Edge, 3 xfailed on Firefox.
  • Negative check: with the set_client_hints_override calls temporarily removed, all 3 tests fail on Chrome (the page reports the real macOS platform instead of the override). Reverted afterwards.
  • ruff check and ruff format --check are clean.

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s): Claude
    • What was generated: the test file, which I reviewed, ran and verified locally
    • I reviewed all AI output and can explain the change

💡 Additional Considerations

  • The tests use the generated _bidi layer because the public selenium.webdriver.common.bidi.UserAgentClientHints is currently generated without any methods. It looks like the command pattern in py/generate_bidi.py (_extract_commands) only matches params: <NamedType>, while the UA Client Hints CDDL declares its params inline (params: { ... }). If that is confirmed, a follow-up could fix the generator and add a matching bidi/user_agent_client_hints_tests.py.
  • Java, .NET and JavaScript also have no tests for this command.

🔄 Types of changes

  • Test additions (no change to shipped code)

Python had no tests for userAgentClientHints.setClientHintsOverride.
Add tests using the generated _bidi layer that check the override is
applied per browsing context and per user context, and that passing
None clears it.
@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@selenium-ci selenium-ci added the C-py Python Bindings label Sep 21, 2026
aayushisabharwal and others added 3 commits September 21, 2026 18:37
Match the other BiDi test files, which mark each test directly
instead of using a module-level pytestmark.
Match emulation_tests.py, where tests read page values through
get_* helpers built on _eval instead of calling _eval directly.
The clear test now also checks that brand and mobile are restored.

@navin772 navin772 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a test for global override where it doesn't passes contexts or user_contexts and assert the expected behaviour

@navin772 navin772 changed the title [py] add BiDi tests for userAgentClientHints [py][bidi]: add BiDi tests for userAgentClientHints Sep 23, 2026
aayushisabharwal and others added 2 commits September 23, 2026 16:33
Covers set_client_hints_override with neither contexts nor
user_contexts, asserting the override reaches the current context and
a browsing context created afterwards.

This branch has not been deployed

No deployments
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.

3 participants