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
43 changes: 43 additions & 0 deletions py/test/selenium/webdriver/common/bidi_browsing_context_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,49 @@ def on_download_will_begin(info):
driver.browsing_context.remove_event_handler("download_will_begin", callback_id)


@pytest.mark.xfail_firefox
def test_add_event_handler_download_end(driver, pages):
"""Test adding event handler for download_end event."""
events_received = []

def on_download_end(info):
events_received.append(info)

callback_id = driver.browsing_context.add_event_handler("download_end", on_download_end)
assert callback_id is not None

context_id = driver.current_window_handle
url = pages.url("downloads/download.html")
driver.browsing_context.navigate(context=context_id, url=url, wait=ReadinessState.COMPLETE)

driver.find_element(By.ID, "file-1").click()

driver.find_element(By.ID, "file-2").click()
WebDriverWait(driver, 5).until(lambda d: len(events_received) == 2)

assert len(events_received) == 2

for ev in events_received:
assert ev.download_params is not None
assert ev.download_params.status == "complete"
assert ev.download_params.context == context_id
assert ev.download_params.timestamp is not None

# we assert that atleast "file_1" is present in the downloaded file since multiple downloads
# will have numbered suffix like file_1 (1)
assert any(
"downloads/file_1.txt" in ev.download_params.url and "file_1" in ev.download_params.filepath
for ev in events_received
)

assert any(
"downloads/file_2.jpg" in ev.download_params.url and "file_2" in ev.download_params.filepath
for ev in events_received
)

driver.browsing_context.remove_event_handler("download_end", callback_id)


def test_add_event_handler_with_specific_contexts(driver):
"""Test adding event handler with specific browsing contexts."""
events_received = []
Expand Down