Set firefox profile protractor

橙三吉。 提交于 2020-01-11 04:13:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!