From 6df5977617bb00c1f6e7a259aaf4d4c3de924d26 Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Thu, 14 May 2026 12:40:25 +0530 Subject: [PATCH 01/14] Add Python BiDi network intercept examples --- .../tests/bidi/test_network_commands.py | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 examples/python/tests/bidi/test_network_commands.py diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py new file mode 100644 index 000000000000..b3ec4e05396e --- /dev/null +++ b/examples/python/tests/bidi/test_network_commands.py @@ -0,0 +1,65 @@ +# 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 + + +@pytest.mark.driver_type("bidi") +def test_add_intercept(driver): + intercept = driver.network._add_intercept() + assert intercept is not None + + +@pytest.mark.driver_type("bidi") +def test_remove_intercept(driver): + 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): + import time + from selenium.webdriver.common.bidi.network import Request + + failed = [] + + def on_request(request: Request): + failed.append(request) + + driver.network.add_request_handler("before_request", on_request) + try: + driver.get("https://www.selenium.dev/selenium/web/blank.html") + except Exception: + pass + time.sleep(1) + 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) \ No newline at end of file From 7e1adcc1f7a8bbf812865a168bd90540201ef81d Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Thu, 14 May 2026 13:15:11 +0530 Subject: [PATCH 02/14] Add Python tab references to W3C BiDi network docs --- .../webdriver/bidi/w3c/network.en.md | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md index b4310a46c3d1..09977e48104f 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md @@ -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 @@ -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#L21-L24" >}} +{{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} {{< /tab >}} @@ -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#L27-L31" >}} +{{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} {{< /tab >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} @@ -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#L34-L50" >}} +{{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} {{< /tab >}} @@ -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 @@ -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#L53-L65" >}} +{{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} {{< /tab >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} @@ -200,6 +234,4 @@ This section contains the APIs related to network events. {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} -{{< /tabpane >}} - - +{{< /tabpane >}} \ No newline at end of file From 55e2b79b985406ae693e0a70ef5aac6fce0af8a5 Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Thu, 14 May 2026 13:58:23 +0530 Subject: [PATCH 03/14] fix test_fail_request to actually invoke fail_request and add assertion --- .../python/tests/bidi/test_network_commands.py | 14 +++++++++++--- .../documentation/webdriver/bidi/w3c/network.en.md | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index b3ec4e05396e..37feaffb5780 100644 --- a/examples/python/tests/bidi/test_network_commands.py +++ b/examples/python/tests/bidi/test_network_commands.py @@ -33,20 +33,28 @@ def test_remove_intercept(driver): @pytest.mark.driver_type("bidi") def test_fail_request(driver): - import time from selenium.webdriver.common.bidi.network import Request - failed = [] + failed_requests = [] + + intercept = driver.network._add_intercept() def on_request(request: Request): - failed.append(request) + failed_requests.append(request) + driver.network.fail_request(request.request["requestId"]) driver.network.add_request_handler("before_request", on_request) + try: driver.get("https://www.selenium.dev/selenium/web/blank.html") except Exception: pass + + import time time.sleep(1) + + assert len(failed_requests) > 0 + driver.network._remove_intercept(intercept["intercept"]) driver.network.clear_request_handlers() diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md index 09977e48104f..38607e26d8f2 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md @@ -131,7 +131,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L34-L50" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L34-L58" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -157,7 +157,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L53-L65" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L61-L72" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} From dcfd84b41398f42816c794b06bd9d78de1d951ed Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Thu, 14 May 2026 14:47:39 +0530 Subject: [PATCH 04/14] Address Qodo review: add comments for private APIs, verify handler removal --- examples/python/tests/bidi/test_network_commands.py | 9 ++++++++- .../documentation/webdriver/bidi/w3c/network.en.md | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index 37feaffb5780..e22cf34eb095 100644 --- a/examples/python/tests/bidi/test_network_commands.py +++ b/examples/python/tests/bidi/test_network_commands.py @@ -20,12 +20,16 @@ @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 @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 == [] @@ -70,4 +74,7 @@ def callback(request: 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) \ No newline at end of file + driver.network.remove_request_handler("before_request", callback_id) + assert callback_id not in [ + h for h in driver.network._handlers.get("before_request", []) + ] \ No newline at end of file diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md index 38607e26d8f2..7891f77278a2 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md @@ -19,7 +19,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L21-L24" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L21-L26" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -42,7 +42,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L27-L31" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L29-L35" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -131,7 +131,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L34-L58" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L38-L62" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -157,7 +157,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L61-L72" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L65-L80" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} From ad1316b97cf30666eb7898532b39bdd841772a49 Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Fri, 10 Jul 2026 22:24:26 +0530 Subject: [PATCH 05/14] Address PR review: harden Python BiDi network examples and sync translations 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 --- .../tests/bidi/test_network_commands.py | 32 +++++++++------ .../webdriver/bidi/w3c/network.en.md | 8 ++-- .../webdriver/bidi/w3c/network.ja.md | 38 +++++++++++++++++- .../webdriver/bidi/w3c/network.pt-br.md | 39 +++++++++++++++++-- .../webdriver/bidi/w3c/network.zh-cn.md | 38 +++++++++++++++++- 5 files changed, 132 insertions(+), 23 deletions(-) diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index e22cf34eb095..83a0107c4bff 100644 --- a/examples/python/tests/bidi/test_network_commands.py +++ b/examples/python/tests/bidi/test_network_commands.py @@ -15,7 +15,10 @@ # specific language governing permissions and limitations # under the License. +import time + import pytest +from selenium.webdriver.support.wait import WebDriverWait @pytest.mark.driver_type("bidi") @@ -50,16 +53,16 @@ def on_request(request: Request): driver.network.add_request_handler("before_request", on_request) try: - driver.get("https://www.selenium.dev/selenium/web/blank.html") - except Exception: - pass - - import time - time.sleep(1) + try: + driver.get("https://www.selenium.dev/selenium/web/blank.html") + except Exception: + pass - assert len(failed_requests) > 0 - driver.network._remove_intercept(intercept["intercept"]) - driver.network.clear_request_handlers() + time.sleep(1) + assert len(failed_requests) > 0 + finally: + driver.network._remove_intercept(intercept["intercept"]) + driver.network.clear_request_handlers() @pytest.mark.driver_type("bidi") @@ -74,7 +77,12 @@ def callback(request: Request): callback_id = driver.network.add_request_handler("before_request", callback) assert callback_id is not None + driver.get("https://www.selenium.dev/selenium/web/blank.html") + WebDriverWait(driver, 5).until(lambda _: requests) + assert len(requests) > 0 + driver.network.remove_request_handler("before_request", callback_id) - assert callback_id not in [ - h for h in driver.network._handlers.get("before_request", []) - ] \ No newline at end of file + request_count = len(requests) + + driver.get("https://www.selenium.dev/selenium/web/blank.html") + assert len(requests) == request_count diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md index 7891f77278a2..5db2b287e6f5 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md @@ -19,7 +19,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L21-L26" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L24-L29" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -42,7 +42,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L29-L35" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L32-L38" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -131,7 +131,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L38-L62" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L65" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -157,7 +157,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L65-L80" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L68-L88" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md index b8b76a827b99..7e3f40054308 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md @@ -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 @@ -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#L24-L29" >}} +{{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} {{< /tab >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} @@ -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 @@ -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-L88" >}} +{{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} {{< /tab >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md index ce3f5d5508e5..c68a849f2cf7 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md @@ -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 @@ -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#L24-L29" >}} +{{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} {{< /tab >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} @@ -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 @@ -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-L88" >}} +{{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} {{< /tab >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} @@ -211,4 +245,3 @@ This section contains the APIs related to network events. {{< badge-code >}} {{< /tab >}} {{< /tabpane >}} - diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md index 7788c2d76396..55ee45e858c6 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md @@ -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 @@ -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#L24-L29" >}} +{{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} {{< /tab >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} @@ -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 @@ -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-L88" >}} +{{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} {{< /tab >}} @@ -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 >}} @@ -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 >}} @@ -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 >}} From 0495a2eb6bcac9df7a906324bfe4e5a2df1b1828 Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Fri, 10 Jul 2026 22:33:18 +0530 Subject: [PATCH 06/14] Address Qodo follow-up: replace sleep and harden BiDi network waits Expect TimeoutException for failed navigation, drop time.sleep, and use a negative WebDriverWait after handler removal. Co-authored-by: Cursor --- examples/python/tests/bidi/test_network_commands.py | 13 +++++-------- .../documentation/webdriver/bidi/w3c/network.en.md | 8 ++++---- .../documentation/webdriver/bidi/w3c/network.ja.md | 8 ++++---- .../webdriver/bidi/w3c/network.pt-br.md | 8 ++++---- .../webdriver/bidi/w3c/network.zh-cn.md | 8 ++++---- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index 83a0107c4bff..a1b3eea0d498 100644 --- a/examples/python/tests/bidi/test_network_commands.py +++ b/examples/python/tests/bidi/test_network_commands.py @@ -15,9 +15,8 @@ # specific language governing permissions and limitations # under the License. -import time - import pytest +from selenium.common.exceptions import TimeoutException from selenium.webdriver.support.wait import WebDriverWait @@ -53,12 +52,9 @@ def on_request(request: Request): driver.network.add_request_handler("before_request", on_request) try: - try: + driver.set_page_load_timeout(5) + with pytest.raises(TimeoutException): driver.get("https://www.selenium.dev/selenium/web/blank.html") - except Exception: - pass - - time.sleep(1) assert len(failed_requests) > 0 finally: driver.network._remove_intercept(intercept["intercept"]) @@ -85,4 +81,5 @@ def callback(request: Request): request_count = len(requests) driver.get("https://www.selenium.dev/selenium/web/blank.html") - assert len(requests) == request_count + with pytest.raises(TimeoutException): + WebDriverWait(driver, 1).until(lambda _: len(requests) > request_count) diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md index 5db2b287e6f5..0f4f3163f3a0 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md @@ -19,7 +19,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L24-L29" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L28" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -42,7 +42,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L32-L38" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L31-L37" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -131,7 +131,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L65" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L61" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -157,7 +157,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L68-L88" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L64-L85" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md index 7e3f40054308..761cc99a3639 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md @@ -29,7 +29,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L24-L29" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L28" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -52,7 +52,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L32-L38" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L31-L37" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -141,7 +141,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L65" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L61" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -167,7 +167,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L68-L88" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L64-L85" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md index c68a849f2cf7..3ffb9979ec93 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md @@ -29,7 +29,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L24-L29" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L28" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -52,7 +52,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L32-L38" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L31-L37" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -141,7 +141,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L65" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L61" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -167,7 +167,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L68-L88" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L64-L85" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md index 55ee45e858c6..b322a77dda24 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md @@ -29,7 +29,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L24-L29" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L28" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -52,7 +52,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L32-L38" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L31-L37" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -141,7 +141,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L65" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L61" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -167,7 +167,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L68-L88" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L64-L85" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} From dbbc57f3eeb440c6b5becd13853a4e55000b88ab Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Fri, 10 Jul 2026 22:58:23 +0530 Subject: [PATCH 07/14] Add trailing newline to network.en.md Address Qodo hygiene comment on PR 2639. Co-authored-by: Cursor --- .../content/documentation/webdriver/bidi/w3c/network.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md index 0f4f3163f3a0..47a2ebca00e5 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md @@ -234,4 +234,4 @@ This section contains the APIs related to network events. {{< tab header="Kotlin" >}} {{< badge-code >}} {{< /tab >}} -{{< /tabpane >}} \ No newline at end of file +{{< /tabpane >}} From 2e6b273a4dcd67f8e69edee3d79d0326e53cc635 Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Fri, 10 Jul 2026 23:05:50 +0530 Subject: [PATCH 08/14] Validate intercept before fail_request cleanup Assert intercept exists and use intercept_id in finally so teardown cannot mask the original failure. Co-authored-by: Cursor --- examples/python/tests/bidi/test_network_commands.py | 4 +++- .../content/documentation/webdriver/bidi/w3c/network.en.md | 4 ++-- .../content/documentation/webdriver/bidi/w3c/network.ja.md | 4 ++-- .../content/documentation/webdriver/bidi/w3c/network.pt-br.md | 4 ++-- .../content/documentation/webdriver/bidi/w3c/network.zh-cn.md | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index a1b3eea0d498..a3162f8c1805 100644 --- a/examples/python/tests/bidi/test_network_commands.py +++ b/examples/python/tests/bidi/test_network_commands.py @@ -44,6 +44,8 @@ def test_fail_request(driver): failed_requests = [] intercept = driver.network._add_intercept() + assert intercept is not None + intercept_id = intercept["intercept"] def on_request(request: Request): failed_requests.append(request) @@ -57,7 +59,7 @@ def on_request(request: Request): driver.get("https://www.selenium.dev/selenium/web/blank.html") assert len(failed_requests) > 0 finally: - driver.network._remove_intercept(intercept["intercept"]) + driver.network._remove_intercept(intercept_id) driver.network.clear_request_handlers() diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md index 47a2ebca00e5..be58a5668015 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md @@ -131,7 +131,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L61" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L63" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -157,7 +157,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L64-L85" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L66-L87" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md index 761cc99a3639..827d62afa866 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md @@ -141,7 +141,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L61" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L63" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -167,7 +167,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L64-L85" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L66-L87" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md index 3ffb9979ec93..a2027ab84e79 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md @@ -141,7 +141,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L61" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L63" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -167,7 +167,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L64-L85" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L66-L87" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md index b322a77dda24..d522806b1175 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md @@ -141,7 +141,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L61" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L63" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -167,7 +167,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L64-L85" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L66-L87" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} From 8a84a1883445fce83256c800d394d825ea1d3fd3 Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Sat, 11 Jul 2026 08:46:37 +0530 Subject: [PATCH 09/14] fix(test): clean up intercept in test_add_intercept, wait for async callback in test_fail-request, fix fail_request call site --- examples/python/tests/bidi/test_network_commands.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index a3162f8c1805..0757ed62fca2 100644 --- a/examples/python/tests/bidi/test_network_commands.py +++ b/examples/python/tests/bidi/test_network_commands.py @@ -26,6 +26,7 @@ def test_add_intercept(driver): # 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") @@ -49,7 +50,7 @@ def test_fail_request(driver): def on_request(request: Request): failed_requests.append(request) - driver.network.fail_request(request.request["requestId"]) + request.fail_request() driver.network.add_request_handler("before_request", on_request) @@ -57,6 +58,7 @@ def on_request(request: Request): driver.set_page_load_timeout(5) with pytest.raises(TimeoutException): driver.get("https://www.selenium.dev/selenium/web/blank.html") + WebDriverWait(driver, 5).until(lambda _: len(failed_requests) > 0) assert len(failed_requests) > 0 finally: driver.network._remove_intercept(intercept_id) From 3a7f25f8eeb47962e4fcfb77654f5214379b0eb2 Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Sat, 11 Jul 2026 13:15:53 +0530 Subject: [PATCH 10/14] =?UTF-8?q?=C2=96update=20network=20docs=20gh-codebl?= =?UTF-8?q?ock=20line=20ranges=20for=20python=20examples=20-=20align=20en/?= =?UTF-8?q?ja/pt-br/zh-cn=20refernences=20with=20the=20current=20test=5Fne?= =?UTF-8?q?twork=5Fcommands.py=20line=20numbers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../documentation/webdriver/bidi/w3c/network.en.md | 8 ++++---- .../documentation/webdriver/bidi/w3c/network.ja.md | 8 ++++---- .../documentation/webdriver/bidi/w3c/network.pt-br.md | 8 ++++---- .../documentation/webdriver/bidi/w3c/network.zh-cn.md | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md index be58a5668015..9710a3ecfa3d 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.en.md @@ -19,7 +19,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L28" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L29" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -42,7 +42,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L31-L37" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L32-L38" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -131,7 +131,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L63" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L65" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -157,7 +157,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L66-L87" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L68-L89" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md index 827d62afa866..096a80891b43 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.ja.md @@ -29,7 +29,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L28" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L29" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -52,7 +52,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L31-L37" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L32-L38" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -141,7 +141,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L63" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L65" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -167,7 +167,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L66-L87" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L68-L89" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md index a2027ab84e79..738a7269dfc5 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.pt-br.md @@ -29,7 +29,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L28" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L29" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -52,7 +52,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L31-L37" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L32-L38" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -141,7 +141,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L63" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L65" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -167,7 +167,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L66-L87" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L68-L89" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} diff --git a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md index d522806b1175..1e2f92aa7225 100644 --- a/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/bidi/w3c/network.zh-cn.md @@ -29,7 +29,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L28" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L23-L29" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -52,7 +52,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L31-L37" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L32-L38" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -141,7 +141,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L63" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L65" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -167,7 +167,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.32" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L66-L87" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L68-L89" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} From a86e03e0657079f7f1a956542f68685c04eec03f Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Sat, 11 Jul 2026 21:40:33 +0530 Subject: [PATCH 11/14] test: skip test_add_and_remove_request_handler due to thread-safety race in Selenium's BiDi websocket_connection.py --- examples/python/tests/bidi/test_network_commands.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index 0757ed62fca2..b7646a8df84d 100644 --- a/examples/python/tests/bidi/test_network_commands.py +++ b/examples/python/tests/bidi/test_network_commands.py @@ -63,8 +63,16 @@ def on_request(request: Request): finally: driver.network._remove_intercept(intercept_id) driver.network.clear_request_handlers() - - + + +@pytest.mark.skip( + reason="request.continue_request() called from the BiDi event callback thread " + "races with the main thread's WebDriver calls on the shared websocket " + "connection, causing an intermittent KeyError in websocket_connection.py's " + "execute() (self._messages.pop(current_id)). Reproduced consistently in " + "isolation, not CI flakiness. Appears to be a thread-safety issue in the " + "Python BiDi client itself — see PR #2639 discussion." +) @pytest.mark.driver_type("bidi") def test_add_and_remove_request_handler(driver): from selenium.webdriver.common.bidi.network import Request @@ -73,6 +81,7 @@ def test_add_and_remove_request_handler(driver): def callback(request: Request): requests.append(request) + request.continue_request() callback_id = driver.network.add_request_handler("before_request", callback) assert callback_id is not None From 6afbf2b5c934618d1f2df9361a4f07d09d56014f Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Sun, 12 Jul 2026 20:40:44 +0530 Subject: [PATCH 12/14] Fix BiDi network examples: remove skip, align with upstream test patterns --- .../tests/bidi/test_network_commands.py | 50 ++++++++----------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index b7646a8df84d..c4ac8baf872a 100644 --- a/examples/python/tests/bidi/test_network_commands.py +++ b/examples/python/tests/bidi/test_network_commands.py @@ -16,7 +16,7 @@ # under the License. import pytest -from selenium.common.exceptions import TimeoutException +from selenium.common.exceptions import WebDriverException from selenium.webdriver.support.wait import WebDriverWait @@ -40,39 +40,36 @@ def test_remove_intercept(driver): @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 failed_requests = [] - intercept = driver.network._add_intercept() - assert intercept is not None - intercept_id = intercept["intercept"] - def on_request(request: Request): - failed_requests.append(request) - request.fail_request() + try: + request.fail_request() + failed_requests.append(request) + except WebDriverException: + # The subscription delivers an event for every request, and some + # are already cancelled by the time we try to fail them (for + # example, once the aborted navigation tears them down). + pass driver.network.add_request_handler("before_request", on_request) try: - driver.set_page_load_timeout(5) - with pytest.raises(TimeoutException): - driver.get("https://www.selenium.dev/selenium/web/blank.html") - WebDriverWait(driver, 5).until(lambda _: len(failed_requests) > 0) + 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, + ) + WebDriverWait(driver, 5).until(lambda _: failed_requests) assert len(failed_requests) > 0 finally: - driver.network._remove_intercept(intercept_id) driver.network.clear_request_handlers() - - -@pytest.mark.skip( - reason="request.continue_request() called from the BiDi event callback thread " - "races with the main thread's WebDriver calls on the shared websocket " - "connection, causing an intermittent KeyError in websocket_connection.py's " - "execute() (self._messages.pop(current_id)). Reproduced consistently in " - "isolation, not CI flakiness. Appears to be a thread-safety issue in the " - "Python BiDi client itself — see PR #2639 discussion." -) + + @pytest.mark.driver_type("bidi") def test_add_and_remove_request_handler(driver): from selenium.webdriver.common.bidi.network import Request @@ -81,18 +78,11 @@ def test_add_and_remove_request_handler(driver): def callback(request: Request): requests.append(request) - request.continue_request() callback_id = driver.network.add_request_handler("before_request", callback) assert callback_id is not None - driver.get("https://www.selenium.dev/selenium/web/blank.html") - WebDriverWait(driver, 5).until(lambda _: requests) - assert len(requests) > 0 - driver.network.remove_request_handler("before_request", callback_id) - request_count = len(requests) driver.get("https://www.selenium.dev/selenium/web/blank.html") - with pytest.raises(TimeoutException): - WebDriverWait(driver, 1).until(lambda _: len(requests) > request_count) + assert not requests \ No newline at end of file From 95dd1bf2c9948aca885db653516a861a073c6fd5 Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Sun, 12 Jul 2026 20:52:08 +0530 Subject: [PATCH 13/14] fix for end of the file lint issue to avoid formatting/linting --- examples/python/tests/bidi/test_network_commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index c4ac8baf872a..ca153479846b 100644 --- a/examples/python/tests/bidi/test_network_commands.py +++ b/examples/python/tests/bidi/test_network_commands.py @@ -85,4 +85,5 @@ def callback(request: Request): driver.network.remove_request_handler("before_request", callback_id) driver.get("https://www.selenium.dev/selenium/web/blank.html") - assert not requests \ No newline at end of file + assert not requests + From 4ad89a3d02888687319662f0ad489b2e844f4916 Mon Sep 17 00:00:00 2001 From: Ajith KV Date: Tue, 14 Jul 2026 11:53:54 +0530 Subject: [PATCH 14/14] Update BiDi network examples for selenium 4.46 API --- .../tests/bidi/test_network_commands.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index ca153479846b..a6116e933e40 100644 --- a/examples/python/tests/bidi/test_network_commands.py +++ b/examples/python/tests/bidi/test_network_commands.py @@ -17,7 +17,6 @@ import pytest from selenium.common.exceptions import WebDriverException -from selenium.webdriver.support.wait import WebDriverWait @pytest.mark.driver_type("bidi") @@ -43,19 +42,10 @@ def test_fail_request(driver): from selenium.webdriver.common.bidi.browsing_context import ReadinessState from selenium.webdriver.common.bidi.network import Request - failed_requests = [] + def block_request(request: Request): + request.fail() - def on_request(request: Request): - try: - request.fail_request() - failed_requests.append(request) - except WebDriverException: - # The subscription delivers an event for every request, and some - # are already cancelled by the time we try to fail them (for - # example, once the aborted navigation tears them down). - pass - - driver.network.add_request_handler("before_request", on_request) + driver.network.add_request_handler(["**/blank.html"], block_request) try: with pytest.raises(WebDriverException): @@ -64,8 +54,6 @@ def on_request(request: Request): url="https://www.selenium.dev/selenium/web/blank.html", wait=ReadinessState.COMPLETE, ) - WebDriverWait(driver, 5).until(lambda _: failed_requests) - assert len(failed_requests) > 0 finally: driver.network.clear_request_handlers() @@ -86,4 +74,3 @@ def callback(request: Request): driver.get("https://www.selenium.dev/selenium/web/blank.html") assert not requests -