Skip to content
Merged
Show file tree
Hide file tree
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 May 14, 2026
7e1adcc
Add Python tab references to W3C BiDi network docs
ajithrao2509 May 14, 2026
55e2b79
fix test_fail_request to actually invoke fail_request and add assertion
ajithrao2509 May 14, 2026
dcfd84b
Address Qodo review: add comments for private APIs, verify handler re…
ajithrao2509 May 14, 2026
03db8a2
Merge branch 'trunk' into add-python-bidi-network-examples
ajithrao2509 May 20, 2026
4ae1fa1
Merge branch 'trunk' into add-python-bidi-network-examples
rpallavisharma Jul 9, 2026
ad1316b
Address PR review: harden Python BiDi network examples and sync trans…
ajithrao2509 Jul 10, 2026
0495a2e
Address Qodo follow-up: replace sleep and harden BiDi network waits
ajithrao2509 Jul 10, 2026
35d8edf
Merge branch 'trunk' into add-python-bidi-network-examples
ajithrao2509 Jul 10, 2026
dbbc57f
Add trailing newline to network.en.md
ajithrao2509 Jul 10, 2026
2e6b273
Validate intercept before fail_request cleanup
ajithrao2509 Jul 10, 2026
4051caa
Merge branch 'trunk' into add-python-bidi-network-examples
diemol Jul 10, 2026
fac2108
Merge branch 'trunk' into add-python-bidi-network-examples
diemol Jul 10, 2026
3645954
Merge branch 'trunk' into add-python-bidi-network-examples
diemol Jul 10, 2026
8a84a18
fix(test): clean up intercept in test_add_intercept, wait for async c…
ajithrao2509 Jul 11, 2026
7b4a4d2
Merge branch 'add-python-bidi-network-examples' of https://github.com…
ajithrao2509 Jul 11, 2026
e0782a5
Merge branch 'trunk' into add-python-bidi-network-examples
ajithrao2509 Jul 11, 2026
47da1e8
Merge branch 'trunk' into add-python-bidi-network-examples
diemol Jul 11, 2026
3a7f25f
–update network docs gh-codeblock line ranges for python examples - a…
ajithrao2509 Jul 11, 2026
a86e03e
test: skip test_add_and_remove_request_handler due to thread-safety r…
ajithrao2509 Jul 11, 2026
14af512
Merge branch 'trunk' into add-python-bidi-network-examples
ajithrao2509 Jul 12, 2026
e69f90d
Merge branch 'trunk' into add-python-bidi-network-examples
ajithrao2509 Jul 12, 2026
6afbf2b
Fix BiDi network examples: remove skip, align with upstream test patt…
ajithrao2509 Jul 12, 2026
95dd1bf
fix for end of the file lint issue to avoid formatting/linting
ajithrao2509 Jul 12, 2026
3d0eb81
Merge branch 'trunk' into add-python-bidi-network-examples
diemol Jul 13, 2026
4ad89a3
Update BiDi network examples for selenium 4.46 API
ajithrao2509 Jul 14, 2026
7e852cd
Merge branch 'trunk' into add-python-bidi-network-examples
ajithrao2509 Jul 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions examples/python/tests/bidi/test_network_commands.py
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
Comment thread
ajithrao2509 marked this conversation as resolved.
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aliases: [
---
## Commands

This section contains the APIs related to network commands.
This section contains the APIs related to network commands.

### Add network intercept

Expand All @@ -17,6 +17,10 @@ This section contains the APIs related to network commands.
{{< badge-version version="4.18" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L36-L38" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-version version="4.32" >}}
{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L29" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -36,6 +40,10 @@ This section contains the APIs related to network commands.
{{< badge-version version="4.18" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L46-L50" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-version version="4.32" >}}
{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L32-L38" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -55,6 +63,9 @@ This section contains the APIs related to network commands.
{{< badge-version version="4.18" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L57-L64" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -74,6 +85,9 @@ This section contains the APIs related to network commands.
{{< badge-version version="4.18" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L74-L80" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -93,6 +107,9 @@ This section contains the APIs related to network commands.
{{< badge-version version="4.18" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L90-L96" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -112,6 +129,10 @@ This section contains the APIs related to network commands.
{{< badge-version version="4.18" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L104-L108" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-version version="4.32" >}}
{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L65" >}}
{{< /tab >}}
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -125,7 +146,7 @@ This section contains the APIs related to network commands.

## Events

This section contains the APIs related to network events.
This section contains the APIs related to network events.

### Before Request Sent

Expand All @@ -134,6 +155,10 @@ This section contains the APIs related to network events.
{{< badge-version version="4.15" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkEventsTest.java#L30-L35" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-version version="4.32" >}}
{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L68-L89" >}}
{{< /tab >}}
Comment thread
ajithrao2509 marked this conversation as resolved.
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -153,6 +178,9 @@ This section contains the APIs related to network events.
{{< badge-version version="4.15" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkEventsTest.java#L45-L51" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -172,6 +200,9 @@ This section contains the APIs related to network events.
{{< badge-version version="4.15" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkEventsTest.java#L62-L68" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -191,6 +222,9 @@ This section contains the APIs related to network events.
{{< badge-version version="4.17" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkEventsTest.java#L101-L106" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -201,5 +235,3 @@ This section contains the APIs related to network events.
{{< badge-code >}}
{{< /tab >}}
{{< /tabpane >}}


Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ aliases: [

# Commands

This section contains the APIs related to network commands.
This section contains the APIs related to network commands.

### Add network intercept

Expand All @@ -27,6 +27,10 @@ This section contains the APIs related to network commands.
{{< badge-version version="4.18" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L36-L38" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-version version="4.32" >}}
{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L29" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -46,6 +50,10 @@ This section contains the APIs related to network commands.
{{< badge-version version="4.18" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L46-L50" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-version version="4.32" >}}
{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L32-L38" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -65,6 +73,9 @@ This section contains the APIs related to network commands.
{{< badge-version version="4.18" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L57-L64" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -84,6 +95,9 @@ This section contains the APIs related to network commands.
{{< badge-version version="4.18" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L74-L80" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -103,6 +117,9 @@ This section contains the APIs related to network commands.
{{< badge-version version="4.18" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L90-L96" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -122,6 +139,10 @@ This section contains the APIs related to network commands.
{{< badge-version version="4.18" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L104-L108" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-version version="4.32" >}}
{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L65" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -135,7 +156,7 @@ This section contains the APIs related to network commands.

## Events

This section contains the APIs related to network events.
This section contains the APIs related to network events.

### Before Request Sent

Expand All @@ -144,6 +165,10 @@ This section contains the APIs related to network events.
{{< badge-version version="4.15" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkEventsTest.java#L30-L35" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-version version="4.32" >}}
{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L68-L89" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -163,6 +188,9 @@ This section contains the APIs related to network events.
{{< badge-version version="4.15" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkEventsTest.java#L45-L51" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -182,6 +210,9 @@ This section contains the APIs related to network events.
{{< badge-version version="4.15" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkEventsTest.java#L62-L68" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand All @@ -201,6 +232,9 @@ This section contains the APIs related to network events.
{{< badge-version version="4.17" >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkEventsTest.java#L101-L106" >}}
{{< /tab >}}
{{< tab header="Python" >}}
{{< badge-code >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
{{< badge-code >}}
{{< /tab >}}
Expand Down
Loading
Loading