How can I customize the Firefox browser settings in selenium-webdriver 3.6.0 for automated testing? I need Firefox to download files without prompting and save them to a specific directory.
For Google Chrome, the approach is as follows:
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();
}
However, trying the same method with Firefox by creating a new profile did not work.
I imported the Profile from the Firefox folder
firefoxProfile = require('selenium-webdriver/firefox').Profile;
and set up new capabilities like this:
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();
}
The created profile object looks like this:
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_: []
}
While there are no errors during initialization and all promises are returned correctly by Mocha, the test framework, the prompt dialog still appears when trying to download a file on Firefox.