Welcome to the Question and Answer site for Software Testing Professionals

You can get your queries resolved from Software Testing Professionals.

Ask a Question

Get answers and give answers to questions from other members.

View All Questions

Get votes and earn points to build your reputation in community.

View Hot Questions

0
How do you test a file download in Selenium WebDriver?

Open 1 Answers 30 Views
0 1
We know that its very tricky part to download a file while automating your tests using Selenium. How do you test a file download in Selenium WebDriver?

1 Answer

0
0
Yes, it is easy to download a file using selenium webdriver

===============================================================================

package automation;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.firefox.FirefoxProfile;

import org.testng.annotations.Test;

public class FileDownloadExample {

public static String downloadPath = "E:\\seleniumdownloads";

@Test

public void testDownload() throws Exception {

System.setProperty("webdriver.firefox.marionette","E://Users//Bharat Varshney//workspace//drivers//geckodriver.exe");

WebDriver driver = new FirefoxDriver(FirefoxDriverProfile());

driver.manage().window().maximize();

    driver.get("http://spreadsheetpage.com/index.php/file/C35/P10/");

    driver.findElement(By.linkText("smilechart.xls")).click();

}

public static FirefoxProfile FirefoxDriverProfile() throws Exception {

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference("browser.download.folderList", 2);

profile.setPreference("browser.download.manager.showWhenStarting", false);

profile.setPreference("browser.download.dir", downloadPath);

profile.setPreference("browser.helperApps.neverAsk.openFile",

"text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");

profile.setPreference("browser.helperApps.neverAsk.saveToDisk",

"text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");

profile.setPreference("browser.helperApps.alwaysAsk.force", false);

profile.setPreference("browser.download.manager.alertOnEXEOpen", false);

profile.setPreference("browser.download.manager.focusWhenStarting", false);

profile.setPreference("browser.download.manager.useWindow", false);

profile.setPreference("browser.download.manager.showAlertOnComplete", false);

profile.setPreference("browser.download.manager.closeWhenDone", false);

return profile;

}

}
answered by (672 points)

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

We have resolved 1.2k+ Software Testing queries!

Software Testing Board Weekly update

We will send you handpicked questions that you would love to answer.

View previous campaigns.

Top Contributors

...