If you use Selenium to test your applications with Firefox, You already have been into the case where a test trigger a file download (pdf, excel, png). This don’t block your test but windows can quickly accumulate if your application uses lots of download. Here is the solution.
To resolve this problem you need to edit the default firefox profile and change some properties.
FirefoxProfile profile = new FirefoxProfile() profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.dir", DOWNLOAD_DIR); profile.setPreference("browser.helpersApps.neverAsk.openFile", "application/octet-stream;application/csv;text/csv;application.pdf;image/png:image/jpeg;text/plain" profile.setPreference("browser.helpersApps.neverAsk.saveToDisk", "application/octet-stream;application/csv;text/csv;application.pdf;image/png:image/jpeg;text/plain" profile.setPreference("browser.helpersApps.alwaysAsk.force", false); new FirefoxDriver(profile);
The browser.download.folderList property specifies the directory where files will be downloaded.
- 0 : The user desktop
- 1 : The user download directory
- 2 : A custom directory
Here we choose the custom directory option and we specify a directory with the browser.download.dir property.
browser.helpersApps.neverAsk.openFile and browser.helpersApps.neverAsk.saveToDisk properties specifies which extensions handled by the browser.