Skip to main content

DownloadManager

DownloadManager verifies file downloads during tests. It polls the configured download directory and waits for a file to appear, handling partial downloads gracefully.


Configuration​

testfly.yml
browser:
downloadDir: ./target/downloads # default

Wait for a specific file​

import io.testfly.browser.DownloadManager;

@Test
public void exportCsvTest() {
click(By.id("export-csv"));

File downloaded = DownloadManager.waitForFile("report.csv", 15);
softAssert().that(downloaded.exists(), "Downloaded file should exist");
softAssert().that(downloaded.length() > 0, "Downloaded file should not be empty");
}

Wait for any file​

When the filename is dynamic (e.g. contains a timestamp):

click(By.id("download-invoice"));

File invoice = DownloadManager.waitForAnyFile(15);
softAssert().that(invoice.getName().endsWith(".pdf"), "Downloaded file should be a PDF");

Clean up between tests​

@BeforeMethod
public void cleanDownloads() {
DownloadManager.clearDownloads();
}

How partial downloads are handled​

DownloadManager ignores files with these extensions until they are complete:

ExtensionBrowser
.crdownloadChrome
.partFirefox

A file is only returned once it exists, has a non-zero size, and has no partial-download extension.


Get the download directory​

File dir = DownloadManager.resolveDownloadDir();
System.out.println("Downloads at: " + dir.getAbsolutePath());

The directory is created automatically if it does not exist.