使用现有的Firefox配置文件和用户证书进行量角器自动化测试

时间:2018-10-25 15:39:02

标签: firefox automation protractor

我正在测试的基于Web的应用程序使用相互身份验证;服务器和客户端证书用于访问它。为了自动化针对不同用户的测试,我手动创建了多个Firefox配置文件。针对特定用户的每个配置文件,该配置文件将在导航至应用程序网站时自动选择并使用用户证书。

对于量角器自动化测试,我正在尝试参考测试用户的现有Firefox配置文件目录启动测试,但这在我的实现中没有发生; Firefox不包含用户配置文件的书签(未显示),并且在导航到应用程序网站时由于缺少用户/服务器证书而无法登录。

版本信息

  • 节点:“ 8.12.0”,
  • npm:“ 6.4.1”,
  • 量角器5.4.1
  • 可用的硒独立版本:3.14.0 [最新]
  • webdriver-manager 12.1.0
  • chromedriver版本可用:2.42、2.43 [最新]
  • 可用的geckodriver版本:v0.22.0,v0.23.0 [最新]
  • 将多个Firefox版本安装到独立目录中
    • Firefox 62.0.3(要启动的目标版本)
    • Firefox 52.8.0 ESR
    • Firefox开发版64.0b3

protractor-ff1.conf.js

此conf.js导致Firefox配置文件按预期使用,但随后webdriver松开了与浏览器的连接,因此该测试无法运行;表示浏览器无法导航至baseUrl。从moz:firefoxOptions中删除配置文件args会导致自动化导航到baseUrl,但是随后未使用Firefox配置文件,因此自动化无法访问该应用程序(未安装服务器/用户证书)。

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
   SELENIUM_PROMISE_MANAGER: false,  // using async-await in spec's and POM files
   allScriptsTimeout: 11000,
   specs: ['./e2e/**/*.e2e-spec.ts'],

   directConnect: true,
   baseUrl: 'https://localhost/',

   capabilities: {
       browserName: 'firefox',
       marionette: true,

       'moz:firefoxOptions': {
           binary: 'path/to/firefox.exe',
           'args': ['-profile', 'path/to/Profiles/q9302rdm.FF59default']
       }
   },

输出

PS C:\Users\user1\Documents\myproject> protractor .\protractor-ff1.conf.js --troubleshoot --logLevel DEBUG --stackTrace
[11:32:29] D/launcher - Running with --troubleshoot
[11:32:29] D/launcher - Protractor version: 5.4.1
[11:32:29] D/launcher - Your base url for tests is https://localhost/
beforeLaunch
[11:32:29] I/launcher - Running 1 instances of WebDriver
[11:32:29] I/direct - Using FirefoxDriver directly...
[11:33:30] E/runner - Unable to start a WebDriver session.
[11:33:30] E/launcher - Error: WebDriverError: connection refused
    at Object.throwDecodedError (C:\Users\user1\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:514:15)
    at parseHttpResponse (C:\Users\user1\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:519:13)
    at doSend.then.response (C:\Users\user1\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:441:30)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
[11:33:30] E/launcher - Process exited with error code 100

protractor-ff2.conf.js

这个有点混乱,但是一直在尝试多次迭代。此conf.js导致自动导航到baseUrl,但不使用Firefox配置文件,因此无法访问该应用程序。我从示例中尝试了多种代码变体,并查看了'selenium-webdriver / firefox'文档。我相信我使用的API错误,但是我不确定自己的状态或如何纠正它。

const { SpecReporter } = require('jasmine-spec-reporter');
var FirefoxProfile = require('selenium-webdriver/firefox').Profile;
var FirefoxOptions = require('selenium-webdriver/firefox').Options;
var q = require('q');

var makeFirefoxProfile = function (preferenceMap) {
SELENIUM_PROMISE_MANAGER: false,  // using async-await in spec's and POM files
    var profile = new FirefoxProfile();
    var options = new FirefoxOptions();

    options.setProfile('C:/Users/user1/AppData/Roaming/Mozilla/Firefox/Profiles/q9302rdm.FF59default');

    profile.acceptUntrustedCerts(true);

    for (var key in preferenceMap) {
        profile.setPreference(key, preferenceMap[key]);
    }
    return q.resolve({
        browserName: 'firefox',
        marionette: true,
        firefox_profile: profile
    });
};

exports.config = {
    SELENIUM_PROMISE_MANAGER: false,  // using async-await in spec's and POM files
    allScriptsTimeout: 11000,
    specs: ['./e2e/**/*.e2e-spec.ts'],

    directConnect: true,
    baseUrl: 'https://localhost/',

    getMultiCapabilities: function () {
        return q.all([
            makeFirefoxProfile({
                // preferences from about:config
                'browser.startup.homepage': 'https://www.google.com'
            }),
        ]);
    },

已引用示例,但仍未成功合并。这一直是我不断搜索的结果,但是我不知道在哪里可以引用现有的个人资料。同样,今天似乎更好的做法是使用selenium-webdriver / firefox代替firefox-profile模块。

背景 我很长时间以来一直在研究和尝试解决此问题,但仍然没有一个完整的“可行”示例。我意识到这可能是一个简单的问题,但是任何推荐的文章或最好的示例都是金!请在这方面需要帮助!

我具有软件开发方面的教育背景,但是我还是编程的新手。

0 个答案:

没有答案