Wait For Download Finished

Wait For Download Finished #

def wait_for_download_finished(
    driver: TestUIDriver,
    file_name: str,
    timeout: int = 1000
) -> None

This command waits until file download is completed or timeout is exceeded. This function is useful if download has to be completed before the end of the test. Download completion check is done every 500 ms, so it can be used for crude download time measurement as well.

The file_name parameter specifies file name to wait for in downloads directory. This parameter can not be None or empty, otherwise an Error will be thrown.

The timeout parameter specifies time in ms, how long to wait for file download to be completed. If no timeout parameter is provided, default value 1000 ms is used. When timeout is exceeded the function will raise an Py-TestUI error but test execution will continue.

def test(driver: TestUIDriver):
    # Example of waiting for file to be downloaded

    # Open DemoQA upload/download page
    driver.navigate_to("https://demoqa.com/upload-download")
    e(driver, "css", "#app").wait_until_visible()

    download_element = e(driver, "css", "#downloadButton")

    driver.save_screenshot("before_download.png")

    # Start download
    download_element.click()
    wait_for_download_finished(driver, "sampleFile.jpeg", 30 * 1000)

    driver.save_screenshot("after_download.png")