diff --git a/examples/python/tests/bidi/test_network_commands.py b/examples/python/tests/bidi/test_network_commands.py index a6116e933e4..64d166cefe6 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,69 @@ def callback(request: Request): driver.get("https://www.selenium.dev/selenium/web/blank.html") assert not requests + + +@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..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,8 +32,13 @@ 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": + monkeypatch.setenv("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..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 >}} @@ -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#L80-L89" >}} {{< /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#L92-L108" >}} {{< /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#L111-L122" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -131,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 >}} @@ -157,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 >}} @@ -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#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 9956ad529dc..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 >}} @@ -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#L80-L89" >}} {{< /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#L92-L108" >}} {{< /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#L111-L122" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -141,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 >}} @@ -167,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 >}} @@ -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#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 de9567d9481..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 >}} @@ -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#L80-L89" >}} {{< /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#L92-L108" >}} {{< /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#L111-L122" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -141,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 >}} @@ -167,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 >}} @@ -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#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 f1c2678d7b1..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 >}} @@ -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#L80-L89" >}} {{< /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#L92-L108" >}} {{< /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#L111-L122" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}} @@ -141,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 >}} @@ -167,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 >}} @@ -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#L125-L143" >}} {{< /tab >}} {{< tab header="Ruby" >}} {{< badge-code >}}