[py][bidi]: add BiDi tests for userAgentClientHints - #18063
Open
aayushisabharwal wants to merge 6 commits into
Open
aayushisabharwal wants to merge 6 commits into
aayushisabharwal wants to merge 6 commits into
Conversation
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.
Contributor
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
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
reviewed
Sep 23, 2026
navin772
left a comment
Member
There was a problem hiding this comment.
Could we add a test for global override where it doesn't passes contexts or user_contexts and assert the expected behaviour
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 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 addspy/test/selenium/webdriver/common/_bidi/user_agent_client_hints_tests.pywith three tests:test_set_client_hints_override_with_contexts: sets the override for the current browsing context, navigates, and asserts thatnavigator.userAgentDatareports the overriddenplatform,brandsandmobilevalues.test_clear_client_hints_override: asserts the override is applied, then that passingNonerestores 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
_bidi/emulation_tests.py(per context, per user context, reset) and mirrors the Ruby spec.finallyblock, or discarded together with its user context, so it cannot leak into other tests that share the BiDi session.contexts/userContextsscoping, and sendingnullto clear. Browser conformance details such as scope precedence, high-entropy values andSec-CH-UA*headers are left to web-platform-tests.xfail_firefoxbecause Firefox does not implement theuserAgentClientHintsmodule. 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.set_client_hints_overridecalls temporarily removed, all 3 tests fail on Chrome (the page reports the realmacOSplatform instead of the override). Reverted afterwards.ruff checkandruff format --checkare clean.🤖 AI assistance
💡 Additional Considerations
_bidilayer because the publicselenium.webdriver.common.bidi.UserAgentClientHintsis currently generated without any methods. It looks like the command pattern inpy/generate_bidi.py(_extract_commands) only matchesparams: <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 matchingbidi/user_agent_client_hints_tests.py.🔄 Types of changes