Instruction: How to Check That a File Was Downloaded
How it works
- Setup browser.download.folder 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.
 
  
- Restart Screenster (Go to Services -> Select Screenster -> restart it)
 
  
- Go to Parameters tab and add two parameters (fileName – which will be downloaded and downloadFolder – the same, as in settings):
 
  
- Record a test with clicking on the link/button for download target file.
- 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.io.File;
 import org.openqa.selenium.support.ui.FluentWait;
 import java.util.concurrent.TimeUnit;public class SeleniumCommand { 
 public void run(WebDriver driver, Browser browser, Mapparameters) 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
 targetFile.delete();
 }
 }/** 
 * Wait for a file till some timeout (in seconds)
 */
 public void waitForFile(WebDriver driver, File file, long timeout) {
 FluentWaitwait = 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.


