Hello,
I am trying to verify the downloaded file. But, I am unable to download the file to a specific folder. It is going into default downloads. Please, someone, help me.
@Keyword
public void example_VerifyDownloadWithFileName() {
String downloadFilepath = “E:\\seleniumdownloads”;
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put(“profile.default_content_settings.popups”, 0);
chromePrefs.put(“download.default_directory”, downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption(“prefs”, chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver.findElement(By.linkText(“mailmerge.xls”)).click();
Assert.assertTrue(isFileDownloaded(downloadFilepath, “mailmerge.xls”), “Failed to download Expected document”);
}
public boolean isFileDownloaded(String downloadPath, String fileName) {
boolean flag = false;
File dir = new File(downloadPath);
File dir_contents = dir.listFiles();
for (int i = 0; i < dir_contents.length; i++) {
if (dir_contents[i].getName().equals(fileName))
return flag=true;
}
return flag;
}
TC:
WebUI.openBrowser(‘Excel Templates [Free Download]’)
WebUI.maximizeWindow()
//mailMerge = //h1[text()=‘Mail Merge Demo’]/following-sibling::ul//b[text()=‘Download:’]/following-sibling::a
WebUI.click(findTestObject(‘mailMerge’))
CustomKeywords.‘com.prime.FileDownloadVerify.example_VerifyDownloadWithFileName’()