Wait For Download Finished

Wait For Download Finished #

waitForDownloadFinished(String fileName, long timeout)

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 fileName parameter specifies file name to wait for in downloads directory. This parameter can not be null 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 an Error is thrown.

public void testUIWithLoadero() {
    // Example of waiting for file to be downloaded
    // Open TestDevLab press page
    open("https://www.testdevlab.com/newsroom")
        .setElement(byCssSelector("body")).waitFor(10).untilIsVisible()
        .saveScreenshot("testdevlab_press_page.png");
    // Get download item in view
    E(byXpath("//div[contains(text(), 'Visuals')]")).scrollTo().view("");
    E(byCssSelector("body")).saveScreenshot("before_download.png");
    // Start download
    E(byXpath("//div[contains(text(), 'Visuals')]")).click();
    // Wait for download to finish
    waitForDownloadFinished("Assets.zip", 30 * 1000);
    E(byCssSelector("body")).saveScreenshot("after_download.png");
}