Skip to content

Commit 1b7f3b0

Browse files
authored
[py] Add test for BiDi request handlers with classic navigation (#16421)
1 parent d66494e commit 1b7f3b0

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

py/test/selenium/webdriver/common/bidi_network_tests.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,20 @@ def callback(request: Request):
7373

7474

7575
def test_continue_request(driver, pages):
76+
exceptions = []
77+
7678
def callback(request: Request):
77-
request.continue_request()
79+
try:
80+
request.continue_request()
81+
except WebDriverException as e:
82+
exceptions.append(e)
7883

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

8591

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

101107

108+
def test_handler_with_classic_navigation(driver, pages):
109+
"""Verify request handlers also work with classic navigation."""
110+
browser_name = driver.caps["browserName"]
111+
if browser_name.lower() in ("chrome", "microsoftedge"):
112+
pytest.skip(reason=f"Request handlers don't yet work in {browser_name} using classic navigation")
113+
114+
exceptions = []
115+
116+
def callback(request: Request):
117+
try:
118+
request.continue_request()
119+
except WebDriverException as e:
120+
exceptions.append(e)
121+
122+
callback_id = driver.network.add_request_handler("before_request", callback)
123+
assert callback_id is not None, "Request handler not added"
124+
pages.load("formPage.html")
125+
assert len(exceptions) == 0, "Exception raised in handler callback"
126+
127+
102128
@pytest.mark.xfail_chrome(reason="Data URLs in Network requests are not implemented in Chrome yet")
103129
@pytest.mark.xfail_edge(reason="Data URLs in Network requests are not implemented in Edge yet")
104130
@pytest.mark.xfail_firefox(reason="Data URLs in Network requests are not implemented in Firefox yet")
@@ -120,4 +146,4 @@ def callback(request: Request):
120146
time.sleep(1) # give callback time to complete
121147
assert driver.find_element(By.ID, "data-url-image").is_displayed()
122148
assert len(data_requests) > 0, "BiDi event not captured"
123-
assert len(exceptions) == 0, "Exception raised when continuing request in callback"
149+
assert len(exceptions) == 0, "Exception raised when continuing request in handler callback"

0 commit comments

Comments
 (0)