I want to launch the Firefox browser through selenium-webdriver 3.6.0 with some of the default settings of the browser changed. Specifically, I want Firefox to download files, during automated testing, without prompting whether to save or not and to download to a predefined directory other than the default, which is the downloads folder.
The way to do it on google chrome is this:
if (this.bName === 'chrome') {
var cap = Capabilities.chrome();
var options = {
'prefs': {
profile: {
default_content_settings: {
popups: 0,
},
},
download: {
default_directory: path.join(__dirname,
'/../Downloads For Testing'),
}
}
};
var cap = cap.set('chromeOptions', options);
this.browser = new Builder().withCapabilities(cap).build();
}
A relevant try on Firefox, by setting the preferences after creating a new profile, didn't work.
I include the Profile from Firefox folder
firefoxProfile = require('selenium-webdriver/firefox').Profile;
and I build with new capabilities
else if (this.bName === 'firefox') {
var cap = Capabilities.firefox();
var profile = new firefoxProfile;
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir", path.join(__dirname, '/../Downloads For Testing'));
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/html");
cap.set('firefox_profile', profile);
console.log(profile);
this.browser = new Builder().withCapabilities(cap).build();
}
This is the printout of the new profile object:
Profile {
preferences_:
{ 'browser.download.folderList': 2,
'browser.download.manager.showWhenStarting': false,
'browser.download.dir': 'C:\\path\\Downloads For Testing',
'browser.helperApps.neverAsk.saveToDisk': 'text/html' },
template_: undefined,
extensions_: []
}
The browser is initiated with no errors and all promises are returned correctly by mocha, the test framework, until pressing the button to download a file and the normal dialog shows up, so no success.