Add Python examples for W3C BiDi network intercept commands#2639
Conversation
👷 Deploy request for selenium-dev pending review.Visit the deploys page to approve it
|
Review Summary by QodoAdd Python examples for W3C BiDi network intercept commands
WalkthroughsDescription• Add 4 Python test examples for W3C BiDi network commands • Integrate Python code references into network documentation • Include badge-code placeholders for unimplemented features • Support network intercept, request handlers, and event operations Diagramflowchart LR
A["Python Test File"] -->|"4 test functions"| B["Network Commands"]
B -->|"add_intercept"| C["Add Intercept"]
B -->|"remove_intercept"| D["Remove Intercept"]
B -->|"request_handler"| E["Request Handler"]
B -->|"fail_request"| F["Fail Request"]
G["Documentation File"] -->|"references"| A
G -->|"Python tabs"| H["Commands Section"]
G -->|"Python tabs"| I["Events Section"]
File Changes1. examples/python/tests/bidi/test_network_commands.py
|
Code Review by Qodo
Context used 1.
|
|
please add details for all languages. please see the contributing doc - https://www.selenium.dev/documentation/about/contributing/ |
|
Code review by qodo was updated up to the latest commit 4ae1fa1 |
…lations Avoid private _handlers checks, always clean up fail_request in finally, and add Python tabs to ja/pt-br/zh-cn docs. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Code review by qodo was updated up to the latest commit ad1316b |
Expect TimeoutException for failed navigation, drop time.sleep, and use a negative WebDriverWait after handler removal. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Code review by qodo was updated up to the latest commit 0495a2e |
|
Code review by qodo was updated up to the latest commit 35d8edf |
Address Qodo hygiene comment on PR 2639. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Code review by qodo was updated up to the latest commit dbbc57f |
Assert intercept exists and use intercept_id in finally so teardown cannot mask the original failure. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Code review by qodo was updated up to the latest commit 2e6b273 |
Checked both nightly failures, neither is in my changed files. tests/browsers/test_console_log.py fails on Windows nightly with a file-locking PermissionError, and tests/actions/api/test_mouse.py::test_move_by_offset_from_element fails on Ubuntu nightly with a ValueError parsing coordinates. Both look like pre-existing issues on the nightly channel, unrelated to this PR. I did also notice a warning (not a failure) in test_fail_request 'Request' object has no attribute 'fail_request' on nightly which suggests possible API drift between the stable and nightly Selenium builds. |
|
Code review by qodo was updated up to the latest commit 14af512 |
|
No, I don't mean the other failures. I meant the specific test you are adding. |
To directly answer: no, it did not pass for me locally, consistently I ran it in isolation multiple times and it fails the same way each time with the KeyError as I described. Happy to share the exact local run output if useful. Given that, is the skip the right call here, or would you prefer I keep digging into a fix on my end first? |
|
Code review by qodo was updated up to the latest commit e69f90d |
|
Code review by qodo was updated up to the latest commit 6afbf2b |
|
hi @diemol Pushed an update that removes the skip and fixes the underlying issues. Summary of what I found and changed: Root cause of the While validating locally, I also found All four tests pass locally on selenium 4.41.0 + Chrome, no skips, no warnings: Docs line ranges updated across all four language pages to match the final file. On the expected CI results: stable should be green on both OSes. The two nightly failures visible on recent runs Note for later: selenium 4.44+ replaced this API with a high-level handler form ( |
|
Code review by qodo was updated up to the latest commit 95dd1bf |
|
So, what was the issue? I tend to avoid reading a copy & pasted text from AI. |
The actual was the examples pin selenium 4.41, which has a threading bug in the BiDi websocket client (no lock on command ids, fixed in selenium 4.44). My callback was sending a command while another event was being processed and the responses collided, that was the KeyError. I rewrote the test the same way selenium's own test_add_and_remove_request_handler works (remove the handler before navigating) so nothing is blocked and the bug never triggers, skip is gone. While retesting I also found test_fail_request was passing without actually failing the request, Chrome rejects failRequest during driver.get, so it now uses browsing_context.navigate like selenium's own tests. All 4 pass locally on 4.41 + Chrome. |
|
Code review by qodo was updated up to the latest commit 3d0eb81 |
|
Interesting. Now we bumped the test suite to 4.46, and this new test is failing again, could you please double check? |
|
Code review by qodo was updated up to the latest commit 7e852cd |
hi @diemol I have made the changes as necessary, earlier when I ran them in my local the selenium version was 4.41, so my validation was against the old pin. On 4.46 the request object has fail() instead of fail_request() which is why the tests broke after the version bump. I rewrote the test_fail_request using the 4.46 handler API same as test_fail_requests_matching_url_pattern in the selenium test suite and verfied the tests locally which are currently passing without any failures on Chrome. Updated the document line ranges as well. |
diemol
left a comment
There was a problem hiding this comment.
Great, thank you for your effort!
Closes #2638
Thanks for contributing to the Selenium site and documentation!
Description
Adds Python test examples for the W3C BiDi Network intercept commands, and mirrors the Python tabs across all translated docs.
Files changed:
examples/python/tests/bidi/test_network_commands.py— new Python test file with 4 testswebsite_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md— Python tab added to each sectionwebsite_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md— Python tabs mirroredwebsite_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md— Python tabs mirroredwebsite_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md— Python tabs mirroredMotivation and Context
The W3C BiDi Network documentation page had Java and JavaScript examples only. Python examples were completely absent — not even a badge-code placeholder. This PR adds Python equivalents for the commands we have tests for, honest badge-code placeholders for the ones we don't, and updates all translated language pages per the contributing guide.
Types of changes
Checklist
@pytest.mark.driver_type("bidi")marker on every testgh-codeblockreferences use verified line numbersbadge-codeplaceholder used honestly where no test exists