【问题标题】:Configuring multiple capabilities with promises使用 Promise 配置多种功能
【发布时间】:2015-01-31 13:39:12
【问题描述】:

这是Set firefox profile with protractor 主题的后续内容。

根据setFirefoxProfile howto,可以使用特殊的"helper" js code 设置一个firefox 配置文件,该配置文件使用firefox-profileq 库来即时制作编码的firefox 配置文件。

这对我有用,直到我尝试使用多个浏览器并配置 multiCapabilities

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',

    multiCapabilities: [
        {
            browserName: 'chrome',
            specs: [
                'footer.disabledCookies.spec.js'
            ],
            chromeOptions: {
                prefs: {
                    'profile.default_content_settings.cookies': 2
                }
            }
        },

        ...
        // other capabilities here
        ...

        helper.getFirefoxProfile()    
     },

     ...
}

使用此设置我遇到了一个错误(完整的回溯 here):

规范模式与任何文件都不匹配。

据我了解,这意味着带有 Firefox 配置文件的设置缺少 specs 键。换句话说,它找不到任何要运行的测试。

我尝试include specs into the capabilities dictionary inside the helper itself,但错误仍然存​​在。

如果使用multiCapabilities,如何修复错误并设置firefox配置文件?


作为一种解决方法,我创建了一个单独的量角器配置文件,仅配置了 firefox(使用 capabilities)并将 grunt 设置为运行量角器两次 - 一个用于此“带有配置文件的 firefox”配置和另一个适用于所有其他浏览器。

【问题讨论】:

  • 我打开了一个问题github.com/angular/protractor/issues/1594。我认为这是你想要的。请对此问题发表评论并使用它来跟踪更新。
  • @hankduan 非常感谢您详细说明此功能请求。请回答(您在 github 问题中提供的一些技术细节),我会接受。如果该功能将被实施,我们将使用适当的说明更新答案。

标签: javascript angularjs firefox selenium protractor


【解决方案1】:

目前,如果我们不使用多能力,量角器只能接受承诺作为能力。这样做的原因是因为 multiCapabilities 在一个新进程中运行每个任务,所以不能传递承诺(函数)(单个能力有效,因为我们没有分叉)。

或者,我们可以在启动器中解析功能,然后将解析的功能传递给新进程;但是,这将破坏设置代理 (https://github.com/angular/protractor/pull/1040) 的能力,这依赖于在 driverProvider 设置后解决的能力承诺。

我想不出一个简单的方法来做到这一点(没有大的重构),但它绝对是可行的。 我为 Protractor (https://github.com/angular/protractor/issues/1594) 创建了一个问题。如果这是您需要的或者您有其他想法来实现它,请关注和/或评论它。

现在您需要使用您在原始问题中提到的解决方法。

更新

https://github.com/angular/protractor/pull/1629 支持这一点。从量角器 1.6 开始(或者如果您同步到 master),您可以将函数传递给 config.getMultiCapabilities,例如 onPrepareonCleanup。这个函数可以返回一个承诺给multiCapabilties(即capabilities的数组)。

有关示例,请参阅 https://github.com/angular/protractor/blob/master/spec/getCapabilitiesConf.js

【讨论】:

  • 太棒了,试过了——它有效! (我已经添加了一个答案,其中包含一个示例,说明我如何使用getMultiCapabilities() 配置量角器)将奖励您额外的赏金。再次感谢!
【解决方案2】:

根据@hankduan 发送的pull request,以下是我如何使用getMultiCapabilities() 组合不同的功能,其中一个是承诺(需要设置firefox-profile):

"use strict";

var FirefoxProfile = require("firefox-profile");
var q = require("q");

exports.config = {
    seleniumAddress: "http://127.0.0.1:4444/wd/hub",

    getMultiCapabilities: function() {
        var deferred = q.defer();

        var multiCapabilities = [
            {
                browserName: "chrome",
                specs: [
                    "footer.disabledCookies.spec.js"
                ],
                chromeOptions: {
                    prefs: {
                        "profile.default_content_settings.cookies": 2
                    }
                }
            },
            {
                browserName: "chrome",
                specs: [
                    "*.spec.js"
                ],
                exclude: [
                    "footer.disabledCookies.spec.js",
                    "footer.disabledJavascript.spec.js",
                    "footer.disabledFlash.spec.js"
                ]
            },
            {
                browserName: "chrome",
                specs: [
                    "footer.disabledFlash.spec.js"
                ],
                chromeOptions: {
                    args: [
                        "--disable-internal-flash",
                        "--disable-bundled-ppapi-flash",
                        "--disable-plugins-discovery"
                    ]
                }
            }
        ];

        // Wait for a server to be ready or get capabilities asynchronously.
        setTimeout(function() {
            var firefoxProfile = new FirefoxProfile();
            firefoxProfile.setPreference("javascript.enabled", false);
            firefoxProfile.encoded(function (encodedProfile) {
                var capabilities = {
                    "browserName": "firefox",
                    "firefox_profile": encodedProfile,
                    "specs": [
                        "footer.disabledJavascript.spec.js"
                    ]
                };
                multiCapabilities.push(capabilities);
                deferred.resolve(multiCapabilities);
            });
        }, 1000);

        return deferred.promise;
    },

    ...

};

希望这对将来的某人有所帮助。

【讨论】:

  • 感谢您的示例。 (一件事:你不需要 setTimeout)
  • @hankduan 不知道为什么,但没有setTimeout() protractor 正在退出,错误代码为 100(虽然没有失败的测试)。这是complete tracebacksetTimeout() 没有错误,工作正常。
猜你喜欢
  • 1970-01-01
  • 2021-06-19
  • 2015-05-03
  • 1970-01-01
  • 2021-01-29
  • 2020-08-03
  • 2018-10-06
  • 1970-01-01
  • 2019-09-07
相关资源
最近更新 更多