简体   繁体   English

设置firefox配置文件量角器

[英]Set firefox profile protractor

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. 但它显示错误: 错误:TypeError:profile.getTemplateDir不是一个我不知道如何解决它的函数

it seems like selenium-webdriver (which is used by protractor ) used to accept a base64 encoded string firefox_profile capability property. 看起来像selenium-webdriver (由protractor使用)用于接受base64编码的字符串firefox_profile功能属性。 But now it expects a selenium-webdriver/firefox . 但现在它需要一个selenium-webdriver/firefox Profile instance. Profile实例。 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. 请注意,不再需要firefox-profile包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM