From 246387321d40915017c0b561c21a12b69ae0cfb1 Mon Sep 17 00:00:00 2001 From: Diego Molina Date: Thu, 23 Jul 2026 13:54:57 +0200 Subject: [PATCH 1/3] Add Python BiDi examples for Register Basic Auth (network.authRequired) Fills the last Python gaps on the Network Commands/Events doc for the authRequired phase: continuing with credentials, continuing without credentials, cancelling, and the Auth Required event. driver.network.add_auth_handler()/add_authentication_handler() are Chrome-only-hanging when the browser falls back to its native prompt: Chrome does not expose that dialog as a WebDriver Alert, so a test that needs to dismiss or observe it deadlocks. Java and JavaScript already work around this by running these specific scenarios against Firefox; this adds a matching "firefox_bidi" driver_type to conftest.py and uses it only for the four new tests, leaving the existing Chrome-based bidi tests untouched. Co-Authored-By: Claude Sonnet 5 --- .../tests/bidi/test_network_commands.py | 73 +++++++++++++++++++ examples/python/tests/conftest.py | 8 ++ .../webdriver/bidi/w3c/network.en.md | 12 ++- .../webdriver/bidi/w3c/network.ja.md | 12 ++- .../webdriver/bidi/w3c/network.pt-br.md | 12 ++- .../webdriver/bidi/w3c/network.zh-cn.md | 12 ++- 6 files changed, 113 insertions(+), 16 deletions(-) diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index a6116e933e4..e7be1dcb7dc 100644 --- a/examples/python/tests/bidi/test_network_commands.py +++ b/examples/python/tests/bidi/test_network_commands.py @@ -17,6 +17,7 @@ import pytest from selenium.common.exceptions import WebDriverException +from selenium.webdriver.common.by import By @pytest.mark.driver_type("bidi") @@ -74,3 +75,75 @@ def callback(request: Request): driver.get("https://www.selenium.dev/selenium/web/blank.html") assert not requests + + +# The following auth-challenge tests use Firefox because Chrome does not +# expose its native basic-auth dialog as a WebDriver Alert, so the fallback +# and cancellation paths would hang waiting on a dialog Selenium can't see +# or dismiss. This mirrors the Java and JavaScript BiDi examples. + + +@pytest.mark.driver_type("firefox_bidi") +def test_continue_with_auth_credentials(driver): + callback_id = driver.network.add_auth_handler("admin", "admin") + + try: + driver.get("https://the-internet.herokuapp.com/basic_auth") + success_message = "Congratulations! You must have the proper credentials." + assert driver.find_element(By.TAG_NAME, "p").text == success_message + finally: + driver.network.remove_auth_handler(callback_id) + + +@pytest.mark.driver_type("firefox_bidi") +def test_continue_without_auth_credentials(driver): + from selenium.webdriver.support import expected_conditions as EC + from selenium.webdriver.support.wait import WebDriverWait + + def callback(request): + pass # Neither provide_credentials() nor cancel(): falls back to the browser's default handling. + + handler_id = driver.network.add_authentication_handler(callback) + + try: + driver.get("https://the-internet.herokuapp.com/basic_auth") + alert = WebDriverWait(driver, 5).until(EC.alert_is_present()) + alert.dismiss() + WebDriverWait(driver, 5).until(lambda d: "Not authorized" in d.page_source) + finally: + driver.network.remove_authentication_handler(handler_id) + + +@pytest.mark.driver_type("firefox_bidi") +def test_cancel_auth(driver): + def callback(request): + request.cancel() + + handler_id = driver.network.add_authentication_handler(callback) + + try: + driver.get("https://the-internet.herokuapp.com/basic_auth") + assert "Not authorized" in driver.page_source + finally: + driver.network.remove_authentication_handler(handler_id) + + +@pytest.mark.driver_type("firefox_bidi") +def test_auth_required_event(driver): + from selenium.webdriver.common.bidi.network import AuthenticationRequest + + challenges = [] + + def callback(request: AuthenticationRequest): + challenges.append(request) + request.provide_credentials("admin", "admin") + + handler_id = driver.network.add_authentication_handler(callback) + + try: + driver.get("https://the-internet.herokuapp.com/basic_auth") + assert len(challenges) == 1 + assert challenges[0].scheme == "Basic" + assert challenges[0].realm == "Restricted Area" + finally: + driver.network.remove_authentication_handler(handler_id) diff --git a/examples/python/tests/conftest.py b/examples/python/tests/conftest.py index d3f26e3def1..f702e35521b 100644 --- a/examples/python/tests/conftest.py +++ b/examples/python/tests/conftest.py @@ -34,6 +34,14 @@ def driver(request): elif driver_type == "firefox": os.environ["MOZ_ENABLE_WAYLAND"] = "0" driver = webdriver.Firefox() + elif driver_type == "firefox_bidi": + # Chrome does not expose its native basic-auth dialog as a WebDriver + # Alert, so auth-challenge tests that need to observe/dismiss it use + # Firefox instead, matching the Java and JavaScript BiDi examples. + os.environ["MOZ_ENABLE_WAYLAND"] = "0" + options = webdriver.FirefoxOptions() + options.enable_bidi = True + driver = webdriver.Firefox(options=options) else: driver = webdriver.Chrome() 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 2f22e05c972..7c534cc0a4e 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 @@ -64,7 +64,8 @@ This section contains the APIs related to network commands. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L57-L64" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L86-L95" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -86,7 +87,8 @@ This section contains the APIs related to network commands. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L74-L80" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L98-L114" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -108,7 +110,8 @@ This section contains the APIs related to network commands. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L90-L96" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L117-L128" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -223,7 +226,8 @@ This section contains the APIs related to network events. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkEventsTest.java#L101-L106" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L131-L149" >}} {{< /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 9956ad529dc..ae82df89909 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 @@ -74,7 +74,8 @@ This section contains the APIs related to network commands. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L57-L64" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L86-L95" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -96,7 +97,8 @@ This section contains the APIs related to network commands. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L74-L80" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L98-L114" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -118,7 +120,8 @@ This section contains the APIs related to network commands. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L90-L96" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L117-L128" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -233,7 +236,8 @@ This section contains the APIs related to network events. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkEventsTest.java#L101-L106" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L131-L149" >}} {{< /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 de9567d9481..6cb4a186a36 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 @@ -74,7 +74,8 @@ This section contains the APIs related to network commands. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L57-L64" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L86-L95" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -96,7 +97,8 @@ This section contains the APIs related to network commands. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L74-L80" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L98-L114" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -118,7 +120,8 @@ This section contains the APIs related to network commands. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L90-L96" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L117-L128" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -233,7 +236,8 @@ This section contains the APIs related to network events. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkEventsTest.java#L101-L106" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L131-L149" >}} {{< /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 f1c2678d7b1..924f72ea2cc 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 @@ -74,7 +74,8 @@ This section contains the APIs related to network commands. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L57-L64" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L86-L95" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -96,7 +97,8 @@ This section contains the APIs related to network commands. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L74-L80" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L98-L114" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -118,7 +120,8 @@ This section contains the APIs related to network commands. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkCommandsTest.java#L90-L96" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L117-L128" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -233,7 +236,8 @@ This section contains the APIs related to network events. {{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/bidirectional/webdriver_bidi/NetworkEventsTest.java#L101-L106" >}} {{< /tab >}} {{< tab header="Python" >}} -{{< badge-code >}} +{{< badge-version version="4.46" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L131-L149" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} From 683d2f03d810b3c0d56f1b3c400b0ebcb520b3d5 Mon Sep 17 00:00:00 2001 From: Diego Molina Date: Thu, 23 Jul 2026 13:58:59 +0200 Subject: [PATCH 2/3] Remove redundant comment in test_network_commands.py Update gh-codeblock line references across en/ja/pt-br/zh-cn to match. Co-Authored-By: Claude Sonnet 5 --- examples/python/tests/bidi/test_network_commands.py | 6 ------ .../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 ++++---- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index e7be1dcb7dc..64d166cefe6 100644 --- a/examples/python/tests/bidi/test_network_commands.py +++ b/examples/python/tests/bidi/test_network_commands.py @@ -77,12 +77,6 @@ def callback(request: Request): assert not requests -# The following auth-challenge tests use Firefox because Chrome does not -# expose its native basic-auth dialog as a WebDriver Alert, so the fallback -# and cancellation paths would hang waiting on a dialog Selenium can't see -# or dismiss. This mirrors the Java and JavaScript BiDi examples. - - @pytest.mark.driver_type("firefox_bidi") def test_continue_with_auth_credentials(driver): callback_id = driver.network.add_auth_handler("admin", "admin") 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 7c534cc0a4e..5d56deb568b 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 @@ -65,7 +65,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L86-L95" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L80-L89" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -88,7 +88,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L98-L114" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L92-L108" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -111,7 +111,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L117-L128" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L111-L122" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -227,7 +227,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L131-L149" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L125-L143" >}} {{< /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 ae82df89909..f8a20eb762c 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 @@ -75,7 +75,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L86-L95" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L80-L89" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -98,7 +98,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L98-L114" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L92-L108" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -121,7 +121,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L117-L128" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L111-L122" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -237,7 +237,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L131-L149" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L125-L143" >}} {{< /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 6cb4a186a36..4cd0eb8c12f 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 @@ -75,7 +75,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L86-L95" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L80-L89" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -98,7 +98,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L98-L114" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L92-L108" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -121,7 +121,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L117-L128" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L111-L122" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -237,7 +237,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L131-L149" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L125-L143" >}} {{< /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 924f72ea2cc..f694c58aed8 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 @@ -75,7 +75,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L86-L95" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L80-L89" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -98,7 +98,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L98-L114" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L92-L108" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -121,7 +121,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L117-L128" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L111-L122" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -237,7 +237,7 @@ This section contains the APIs related to network events. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L131-L149" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L125-L143" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} From 8686a4239a92f96f50b0b8fba3d3c80d4d625e0d Mon Sep 17 00:00:00 2001 From: Diego Molina Date: Thu, 23 Jul 2026 15:01:34 +0200 Subject: [PATCH 3/3] Address Qodo review feedback on PR #2741 - Fix stale gh-codeblock line ranges for the four pre-existing Python sections (Add/Remove intercept, Fail request, Add/remove request handler): adding the By import shifted every line below it by 1, which the previous commits missed since they only tracked the new functions appended at the end of the file. - Use pytest's monkeypatch.setenv instead of raw os.environ mutation for MOZ_ENABLE_WAYLAND, so it's restored after each test instead of leaking into later tests in the same process (applies to both the existing "firefox" and new "firefox_bidi" driver types). Co-Authored-By: Claude Sonnet 5 --- examples/python/tests/conftest.py | 9 +++------ .../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 ++++---- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/examples/python/tests/conftest.py b/examples/python/tests/conftest.py index f702e35521b..a031982393e 100644 --- a/examples/python/tests/conftest.py +++ b/examples/python/tests/conftest.py @@ -23,7 +23,7 @@ def pytest_configure(config): @pytest.fixture(scope='function') -def driver(request): +def driver(request, monkeypatch): marker = request.node.get_closest_marker("driver_type") driver_type = marker.args[0] if marker else None @@ -32,13 +32,10 @@ def driver(request): options.enable_bidi = True driver = webdriver.Chrome(options=options) elif driver_type == "firefox": - os.environ["MOZ_ENABLE_WAYLAND"] = "0" + monkeypatch.setenv("MOZ_ENABLE_WAYLAND", "0") driver = webdriver.Firefox() elif driver_type == "firefox_bidi": - # Chrome does not expose its native basic-auth dialog as a WebDriver - # Alert, so auth-challenge tests that need to observe/dismiss it use - # Firefox instead, matching the Java and JavaScript BiDi examples. - os.environ["MOZ_ENABLE_WAYLAND"] = "0" + monkeypatch.setenv("MOZ_ENABLE_WAYLAND", "0") options = webdriver.FirefoxOptions() options.enable_bidi = True driver = webdriver.Firefox(options=options) 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 5d56deb568b..9cef86da5cb 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#L22-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 >}} @@ -134,7 +134,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L58" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L59" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -160,7 +160,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-L76" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L62-L77" >}} {{< /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 f8a20eb762c..fa72fe30788 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#L22-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 >}} @@ -144,7 +144,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L58" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L59" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -170,7 +170,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-L76" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L62-L77" >}} {{< /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 4cd0eb8c12f..f852207a3f7 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#L22-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 >}} @@ -144,7 +144,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L58" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L59" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -170,7 +170,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-L76" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L62-L77" >}} {{< /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 f694c58aed8..2a46798ffd9 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#L22-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 >}} @@ -144,7 +144,7 @@ This section contains the APIs related to network commands. {{< /tab >}} {{< tab header="Python" >}} {{< badge-version version="4.46" >}} -{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L40-L58" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L41-L59" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -170,7 +170,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-L76" >}} +{{< gh-codeblock path="/examples/python/tests/bidi/test_network_commands.py#L62-L77" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}}