Skip to content
Merged
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
30 changes: 28 additions & 2 deletions py/test/selenium/webdriver/common/bidi_network_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ def callback(request: Request):


def test_continue_request(driver, pages):
exceptions = []

def callback(request: Request):
request.continue_request()
try:
request.continue_request()
except WebDriverException as e:
exceptions.append(e)

callback_id = driver.network.add_request_handler("before_request", callback)
assert callback_id is not None, "Request handler not added"
url = pages.url("formPage.html")
driver.browsing_context.navigate(context=driver.current_window_handle, url=url, wait=ReadinessState.COMPLETE)
assert driver.find_element(By.NAME, "login").is_displayed(), "Request not continued"
assert len(exceptions) == 0, "Exception raised when continuing request in handler callback"


def test_continue_with_auth(driver):
Expand All @@ -99,6 +105,26 @@ def test_remove_auth_handler(driver):
assert driver.network.intercepts == [], "Intercept not removed"


def test_handler_with_classic_navigation(driver, pages):
"""Verify request handlers also work with classic navigation."""
browser_name = driver.caps["browserName"]
if browser_name.lower() in ("chrome", "microsoftedge"):
pytest.skip(reason=f"Request handlers don't yet work in {browser_name} using classic navigation")

exceptions = []

def callback(request: Request):
try:
request.continue_request()
except WebDriverException as e:
exceptions.append(e)

callback_id = driver.network.add_request_handler("before_request", callback)
assert callback_id is not None, "Request handler not added"
pages.load("formPage.html")
assert len(exceptions) == 0, "Exception raised in handler callback"


@pytest.mark.xfail_chrome(reason="Data URLs in Network requests are not implemented in Chrome yet")
@pytest.mark.xfail_edge(reason="Data URLs in Network requests are not implemented in Edge yet")
@pytest.mark.xfail_firefox(reason="Data URLs in Network requests are not implemented in Firefox yet")
Expand All @@ -120,4 +146,4 @@ def callback(request: Request):
time.sleep(1) # give callback time to complete
assert driver.find_element(By.ID, "data-url-image").is_displayed()
assert len(data_requests) > 0, "BiDi event not captured"
assert len(exceptions) == 0, "Exception raised when continuing request in callback"
assert len(exceptions) == 0, "Exception raised when continuing request in handler callback"