Upload file to Firefox with protractor

I need to upload a zip file to Firefox using a protractor. When you click on the download link, a Windows dialog box opens offering to open / save the file. So how can I handle this. What arguments do I need to convey to the driver? With chrome, I can do this using download: {'prompt_for_download': false},

but what should I do with firefox.

+5
source share
1 answer

The problem is that you cannot manipulate this β€œSave As ...” dialog through protractor / selenium. You should avoid opening it in the first place and let firefox automatically download files of a certain type of mime type - in your case application/zip .

In other words, you need to start Firefox using a Firefox profile that sets the appropriate settings :

 var q = require("q"); var FirefoxProfile = require("firefox-profile"); var makeFirefoxProfile = function(preferenceMap, specs) { var deferred = q.defer(); var firefoxProfile = new FirefoxProfile(); for (var key in preferenceMap) { firefoxProfile.setPreference(key, preferenceMap[key]); } firefoxProfile.encoded(function (encodedProfile) { var capabilities = { browserName: "firefox", firefox_profile: encodedProfile, specs: specs }; deferred.resolve(capabilities); }); return deferred.promise; }; exports.config = { getMultiCapabilities: function() { return q.all([ makeFirefoxProfile( { "browser.download.folderList": 2, "browser.download.dir": "/path/to/save/downloads", "browser.helperApps.neverAsk.saveToDisk": "application/zip" }, ["specs/*.spec.js"] ) ]); }, // ... } 

Here we mainly say: Firefox, download zip files automatically without asking in the /path/to/save/downloads directory.

+2
source

All Articles