问题
I try to use this code:
var makeFirefoxProfile = function (preferenceMap) {
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
};
deferred.resolve(capabilities);
});
return deferred.promise;
};
getMultiCapabilities: function () {
return q.all([
makeFirefoxProfile(
{
"browser.download.folderList": 2,
"browser.download.dir": "D:/Automation",
"browser.helperApps.alwaysAsk.force": false
}
)
]);
},
But it show error: Error: TypeError: profile.getTemplateDir is not a function I don't know how to fix it.
回答1:
it seems like selenium-webdriver
(which is used by protractor
) used to accept a base64 encoded string firefox_profile
capability property. But now it expects a selenium-webdriver/firefox
.Profile
instance. So here is how you can solve your issue:
// make sure you have access to the selenium-webdriver firefox Profile class
var FirefoxProfile = require("selenium-webdriver/firefox").Profile;
//...
// then change makeFirefoxProfile() function implementation with the following...
var makeFirefoxProfile = function (preferenceMap) {
var profile = new FirefoxProfile();
for (var key in preferenceMap) {
profile.setPreference(key, preferenceMap[key]);
}
return q.resolve({
browserName: "firefox",
marionette: true,
firefox_profile: profile
});
};
I hope this helps.
Note that firefox-profile
package is no longer needed.
来源:https://stackoverflow.com/questions/42151372/set-firefox-profile-protractor