Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ValchanOficial/5b6b5cf6b9379a456070d2297dd94019 to your computer and use it in GitHub Desktop.
Save ValchanOficial/5b6b5cf6b9379a456070d2297dd94019 to your computer and use it in GitHub Desktop.
Validate Downloaded file after clicking on downloaded button/ link
https://stackoverflow.com/questions/45573483/how-to-check-downloaded-files-selenium-webdriver
http://www.seleniumeasy.com/selenium-tutorials/verify-file-after-downloading-using-webdriver-java
https://stackoverflow.com/questions/30726126/detecting-a-file-downloaded-in-selenium-java
public class FileDownloadVerify {
private WebDriver driver;
private static String downloadPath = "D:\\seleniumdownloads";
private String URL="http://spreadsheetpage.com/index.php/file/C35/P10/";
@BeforeClass
public void testSetup() throws Exception{
driver = new FirefoxDriver(firefoxProfile());
driver.manage().window().maximize();
}
@Test
public void example_VerifyDownloadWithFileName() {
driver.get(URL);
driver.findElement(By.linkText("mailmerge.xls")).click();
Assert.assertTrue(isFileDownloaded(downloadPath, "mailmerge.xls"), "Failed to download Expected document");
}
@Test
public void example_VerifyDownloadWithFileExtension() {
driver.get(URL);
driver.findElement(By.linkText("mailmerge.xls")).click();
Assert.assertTrue(isFileDownloaded_Ext(downloadPath, ".xls"), "Failed to download document which has extension .xls");
}
@Test
public void example_VerifyExpectedFileName() {
driver.get(URL);
driver.findElement(By.linkText("mailmerge.xls")).click();
File getLatestFile = getLatestFilefromDir(downloadPath);
String fileName = getLatestFile.getName();
Assert.assertTrue(fileName.equals("mailmerge.xls"), "Downloaded file name is not matching with expected file name");
}
@AfterClass
public void tearDown() {
driver.quit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment