Skip to content

Commit 0e818ba

Browse files
committed
improve url pattern test
1 parent 232b80f commit 0e818ba

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,27 +323,40 @@ def test_response_handler_with_url_patterns(driver, pages):
323323
all_responses = []
324324

325325
def matched_callback(response: Response):
326+
response.continue_response()
326327
matched_responses.append(response)
327328

328329
def all_callback(response: Response):
329330
all_responses.append(response)
330331

331332
# Add handler with URL pattern - only matches formPage.html
332333
driver.network.add_response_handler(
333-
"response_completed", matched_callback, url_patterns=[{"type": "string", "pattern": "*/formPage.html"}]
334+
"response_started",
335+
matched_callback,
336+
url_patterns=[{"type": "pattern", "pathname": "/formPage.html"}],
337+
intercept=True,
334338
)
335339

336340
# Add handler without pattern - matches all
337-
driver.network.add_response_handler("response_completed", all_callback)
341+
driver.network.add_response_handler("response_started", all_callback)
338342

343+
driver.browsing_context.navigate(
344+
context=driver.current_window_handle, url="https://example.com/", wait=ReadinessState.COMPLETE
345+
)
346+
time.sleep(1)
347+
348+
# initial assertions, there should be 0 matched responses
349+
assert len(matched_responses) == 0
350+
initial_all_responses = len(all_responses)
351+
assert initial_all_responses > 0
352+
353+
# now load formPage.html
339354
url = pages.url("formPage.html")
340355
driver.browsing_context.navigate(context=driver.current_window_handle, url=url, wait=ReadinessState.COMPLETE)
341356

342-
# Wait for events
343357
time.sleep(1)
344358

345-
assert len(matched_responses) <= len(all_responses)
346-
347-
assert len(all_responses) > 0, "No responses captured"
359+
assert len(matched_responses) > 0
360+
assert len(all_responses) > initial_all_responses
348361

349362
driver.network.clear_response_handlers()

0 commit comments

Comments
 (0)