JS Testing Academy · QA Demo Site

Upload & Download

Download a file and verify it on disk, then upload a file and verify the path the application received.

Download

Download sample file

The file is sample-download.txt. In your test, set the browser download folder and then check the file exists on disk.

Upload

Practice tasks

  1. Download the file to a folder you control and assert the file exists with the right name.
  2. Upload a .txt file with sendKeys(path) / setInputFiles() and assert the file name is shown.
  3. Upload an unsupported type such as .exe and assert the error message appears.
  4. Assert that the output shows the file size for a valid upload.
Sample automation code
// set the download folder before creating the driver
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new");
Map<String, Object> prefs = new HashMap<>();
prefs.put("download.default_directory", "/tmp/downloads");
options.setExperimentalOption("prefs", prefs);

driver.findElement(By.id("download-button")).click();
Thread.sleep(1500);
Assert.assertTrue(new File("/tmp/downloads/sample-download.txt").exists());

driver.findElement(By.id("upload-file")).sendKeys("/tmp/upload-me.txt");
Assert.assertTrue(driver.findElement(By.id("uploaded-file-path")).getText().contains("upload-me.txt"));