-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add Python examples for W3C BiDi network intercept commands #2639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
diemol
merged 27 commits into
SeleniumHQ:trunk
from
ajithrao2509:add-python-bidi-network-examples
Jul 14, 2026
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
6df5977
Add Python BiDi network intercept examples
ajithrao2509 7e1adcc
Add Python tab references to W3C BiDi network docs
ajithrao2509 55e2b79
fix test_fail_request to actually invoke fail_request and add assertion
ajithrao2509 dcfd84b
Address Qodo review: add comments for private APIs, verify handler re…
ajithrao2509 03db8a2
Merge branch 'trunk' into add-python-bidi-network-examples
ajithrao2509 4ae1fa1
Merge branch 'trunk' into add-python-bidi-network-examples
rpallavisharma ad1316b
Address PR review: harden Python BiDi network examples and sync trans…
ajithrao2509 0495a2e
Address Qodo follow-up: replace sleep and harden BiDi network waits
ajithrao2509 35d8edf
Merge branch 'trunk' into add-python-bidi-network-examples
ajithrao2509 dbbc57f
Add trailing newline to network.en.md
ajithrao2509 2e6b273
Validate intercept before fail_request cleanup
ajithrao2509 4051caa
Merge branch 'trunk' into add-python-bidi-network-examples
diemol fac2108
Merge branch 'trunk' into add-python-bidi-network-examples
diemol 3645954
Merge branch 'trunk' into add-python-bidi-network-examples
diemol 8a84a18
fix(test): clean up intercept in test_add_intercept, wait for async c…
ajithrao2509 7b4a4d2
Merge branch 'add-python-bidi-network-examples' of https://github.com…
ajithrao2509 e0782a5
Merge branch 'trunk' into add-python-bidi-network-examples
ajithrao2509 47da1e8
Merge branch 'trunk' into add-python-bidi-network-examples
diemol 3a7f25f
update network docs gh-codeblock line ranges for python examples - a…
ajithrao2509 a86e03e
test: skip test_add_and_remove_request_handler due to thread-safety r…
ajithrao2509 14af512
Merge branch 'trunk' into add-python-bidi-network-examples
ajithrao2509 e69f90d
Merge branch 'trunk' into add-python-bidi-network-examples
ajithrao2509 6afbf2b
Fix BiDi network examples: remove skip, align with upstream test patt…
ajithrao2509 95dd1bf
fix for end of the file lint issue to avoid formatting/linting
ajithrao2509 3d0eb81
Merge branch 'trunk' into add-python-bidi-network-examples
diemol 4ad89a3
Update BiDi network examples for selenium 4.46 API
ajithrao2509 7e852cd
Merge branch 'trunk' into add-python-bidi-network-examples
ajithrao2509 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| import pytest | ||
| from selenium.common.exceptions import WebDriverException | ||
|
|
||
|
|
||
| @pytest.mark.driver_type("bidi") | ||
| def test_add_intercept(driver): | ||
| # _add_intercept is currently the available Python API for BiDi network intercepts. | ||
| # This will be updated when a public API is stabilized. | ||
| intercept = driver.network._add_intercept() | ||
| assert intercept is not None | ||
| driver.network._remove_intercept(intercept["intercept"]) | ||
|
|
||
|
|
||
| @pytest.mark.driver_type("bidi") | ||
| def test_remove_intercept(driver): | ||
| # _add_intercept/_remove_intercept are currently the available Python APIs. | ||
| # These will be updated when a public API is stabilized. | ||
| intercept = driver.network._add_intercept() | ||
| driver.network._remove_intercept(intercept["intercept"]) | ||
| assert driver.network.intercepts == [] | ||
|
|
||
|
|
||
| @pytest.mark.driver_type("bidi") | ||
| def test_fail_request(driver): | ||
| from selenium.webdriver.common.bidi.browsing_context import ReadinessState | ||
| from selenium.webdriver.common.bidi.network import Request | ||
|
|
||
| def block_request(request: Request): | ||
| request.fail() | ||
|
|
||
| driver.network.add_request_handler(["**/blank.html"], block_request) | ||
|
|
||
| try: | ||
| with pytest.raises(WebDriverException): | ||
| driver.browsing_context.navigate( | ||
| context=driver.current_window_handle, | ||
| url="https://www.selenium.dev/selenium/web/blank.html", | ||
| wait=ReadinessState.COMPLETE, | ||
| ) | ||
| finally: | ||
| driver.network.clear_request_handlers() | ||
|
|
||
|
|
||
| @pytest.mark.driver_type("bidi") | ||
| def test_add_and_remove_request_handler(driver): | ||
| from selenium.webdriver.common.bidi.network import Request | ||
|
|
||
| requests = [] | ||
|
|
||
| def callback(request: Request): | ||
| requests.append(request) | ||
|
|
||
| callback_id = driver.network.add_request_handler("before_request", callback) | ||
| assert callback_id is not None | ||
|
|
||
| driver.network.remove_request_handler("before_request", callback_id) | ||
|
|
||
| driver.get("https://www.selenium.dev/selenium/web/blank.html") | ||
| assert not requests | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.