Reputation: 625
I'm doing tests of a WebPage using the selenium framework 2.33. the TestCase here should verify the download of a file.
The following code did work with Firefox 21 and older. Since the Update to FF 22, it is no longer working and I have not found out why.
I used it to save a tar.gz file, but txt or CSV files are also failing.
Setup driver:
FirefoxProfile profile = new FirefoxProfile();
profile.AcceptUntrustedCertificates = true;
profile.SetPreference("browser.download.dir", System.Environment.GetEnvironmentVariable("TEMP"));
profile.SetPreference("browser.download.folderList", 2);
profile.SetPreference("browser.download.manager.showWhenStarting", false);
profile.SetPreference("browser.helperApps.alwaysAsk.force", false);
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "text/xml, text/csv, text/plain, text/log, application/zlib, application/x-gzip, application/x-compressed, application/x-gtar, multipart/x-gzip, application/tgz, application/gnutar, application/x-tar");
profile.SetPreference("pdfjs.disabled", true);
IWebDriver webDriver = new FirefoxDriver(profile);
Test:
webDriver.Navigate().GoToUrl("https://example.com/downloadthis.txt");
Note: in firefox 22, "about:config" the line "browser.helperApps.neverAsk.saveToDisk" with the given arguments is present. but despite this, the "save file" dialog pops up and the test is failing when it checks for the expected file at the saving location.
Does anyone have an idea or encountered this too?
edit: formatting
Upvotes: 1
Views: 3782
Reputation: 9
You Can Download All Files (Eg: .xls, .csv, .pdf)
I also face same problem in my application:
I got solution using Robot in java
following code i write to download all file
Thread.sleep(1000L);
//create robot object
Robot robot = new Robot();
Thread.sleep(1000L);
//Click Down Arrow Key to select "Save File" Radio Button
robot.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(1000L);
// Click 3 times Tab to take focus on "OK" Button
robot.keyPress(KeyEvent.VK_TAB);
Thread.sleep(1000L);
robot.keyPress(KeyEvent.VK_TAB);
Thread.sleep(1000L);
robot.keyPress(KeyEvent.VK_TAB);
Thread.sleep(1000L);
//Click "Enter" Button to download file
robot.keyPress(KeyEvent.VK_ENTER);
Thread.sleep(5000L);
System.out.println("Robot work Complete");
Upvotes: 0
Reputation: 625
Ok, with the help of User user1177636 i came to the solution.
Firefox has changed the MIME type of .tar.gz files from FF 21 to 22
old: application/x-gzip new: application/gzip
corrected the line in setup to:
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "text/xml, text/csv, text/plain, text/log, application/zlib, application/x-gzip, application/x-compressed, application/x-gtar, multipart/x-gzip, application/tgz, application/gnutar, application/x-tar, application/gzip");
and it works again!
THX user1177636, i upvoted your comment (if that makes any sense) !
Upvotes: 4