Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions examples/python/tests/bidi/test_network_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import pytest
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.by import By
Comment thread
qodo-code-review[bot] marked this conversation as resolved.


@pytest.mark.driver_type("bidi")
Expand Down Expand Up @@ -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")
Comment thread
diemol marked this conversation as resolved.

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)
9 changes: 7 additions & 2 deletions examples/python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
else:
driver = webdriver.Chrome()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand Down Expand Up @@ -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 >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand Down Expand Up @@ -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 >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand All @@ -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 >}}
Expand Down Expand Up @@ -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 >}}
Expand Down
Loading
Loading