Add Python BiDi examples for Register Basic Auth (network.authRequired) - #2741
Conversation
Fills the last Python gaps on the Network Commands/Events doc for the authRequired phase: continuing with credentials, continuing without credentials, cancelling, and the Auth Required event. driver.network.add_auth_handler()/add_authentication_handler() are Chrome-only-hanging when the browser falls back to its native prompt: Chrome does not expose that dialog as a WebDriver Alert, so a test that needs to dismiss or observe it deadlocks. Java and JavaScript already work around this by running these specific scenarios against Firefox; this adds a matching "firefox_bidi" driver_type to conftest.py and uses it only for the four new tests, leaving the existing Chrome-based bidi tests untouched. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
PR Summary by QodoAdd Python BiDi Basic Auth (network.authRequired) examples + Firefox BiDi test driver
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
✅ Deploy Preview for selenium-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Update gh-codeblock line references across en/ja/pt-br/zh-cn to match. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Code Review by Qodo
Context used✅ Compliance rules (platform):
10 rules 1. admin credentials hard-coded
|
|
Code review by qodo was updated up to the latest commit b35de08 |
- Fix stale gh-codeblock line ranges for the four pre-existing Python sections (Add/Remove intercept, Fail request, Add/remove request handler): adding the By import shifted every line below it by 1, which the previous commits missed since they only tracked the new functions appended at the end of the file. - Use pytest's monkeypatch.setenv instead of raw os.environ mutation for MOZ_ENABLE_WAYLAND, so it's restored after each test instead of leaking into later tests in the same process (applies to both the existing "firefox" and new "firefox_bidi" driver types). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Code review by qodo was updated up to the latest commit 8686a42 |
Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.
Description
Adds Python examples for the BiDi
network.authRequiredphase toexamples/python/tests/bidi/test_network_commands.py, and wires up the four remainingPython{{< badge-code >}}placeholders on the Network Commands/Events doc (en, ja, pt-br, zh-cn):test_continue_with_auth_credentials)test_continue_without_auth_credentials)test_cancel_auth)test_auth_required_event)Motivation and Context
Reported in #815 ("Please add sample python code for BiDi APIs Register Basic Auth and Network Interception"). Some other Network sections have gained Python examples since 2021, but the "Register Basic Auth" scenarios specifically were still
{{< badge-code >}}placeholders.seleniumalready has purpose-built Python APIs for this —driver.network.add_auth_handler(username, password)and the more flexibledriver.network.add_authentication_handler(callback)(withAuthenticationRequest.provide_credentials()/.cancel()) — they just had no doc example or test coverage.Why a new
firefox_bididriver typeThe "without credentials" and "cancel" scenarios fall back to (or trigger failure of) the browser's native basic-auth prompt. Chrome does not expose that native dialog as a WebDriver
Alert, so a test that waits for/dismisses it deadlocks — I hit this directly (driver.get()hung indefinitely on Chrome). The Java and JavaScript examples for these same scenarios already work around this by using Firefox specifically. I added a matchingfirefox_bidioption to thedriver_typefixture inconftest.pyand used it only for these four new tests; the existing Chrome-basedbiditests are untouched.All 8 tests in the file (4 existing + 4 new) pass consistently against real Chrome/Firefox browsers, run 3x with no flakiness.
Types of changes
Checklist
Closes #815.