Show Table of Content

Instruction: How to Check That a File Was Downloaded

How it works

  1. Setup variable to a required folder. For example D:\downloads.
    It will work only for local installation because on cloud/demo user can access to filesystem and do whatever he want.
    Visual Regression Testing: download settings
  2. Restart Screenster (Go to Services -> Select Screenster -> restart it)
    Visual Regression Testing: restart service
  3. Go to Parameters tab and add two parameters (fileName – which will be downloaded and downloadFolder – the same, as in settings):
    Visual Regression Testing: restart service
  4. Record a test with clicking on the link/button for download target file.
  5. Add Selenium command after Click command with the next code:

    package commands;

    import com.agileengine.screenster.logic.browsers.Browser;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.By;
    import org.testng.Assert;
    import java.util.Map;
    import utils.Screenster;
    import java.util.concurrent.TimeUnit;

    public class SeleniumCommand {
     public void run(WebDriver driver, Browser browser, Map parameters) throws Exception {
      //get folder and file name from parameters
      String fileName = parameters.get(“fileName”);
      String downloadFolder = parameters.get(“downloadFolder”);
      File targetFile = new File(downloadFolder, fileName);
      //max time to download in seconds
      int downloadTime = 20;
      waitForFile(driver, targetFile, downloadTime);
      //if file is not present – fail test
      if (!targetFile.exists()) {
       Screenster.failTest(“File is not present”);
      } else {
       //delete file to be sure that next time new file will be downloaded

     * Wait for a file till some timeout (in seconds)
     public void waitForFile(WebDriver driver, File file, long timeout) {
      FluentWait wait = new FluentWait(driver)
       .withTimeout(timeout, TimeUnit.SECONDS)
       .pollingEvery(1, TimeUnit.SECONDS);
      wait.until((webDriver) -> file.exists());

    You can increase downloadTime if needed.

You can also visit the Release History page to check what’s new and what has been improved in your current Screenster version.

Want to try Screenster on the cloud?

Try Online


WordPress Image Lightbox Plugin