这是 Set firefox profile with protractor 的后续行动话题。
根据setFirefoxProfile
howto,可以使用特殊的 "helper" js code 设置 firefox 配置文件使用 firefox-profile
和 q
动态制作编码的 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 ):
Spec patterns did not match any files.
据我了解,这意味着使用 firefox 配置文件的设置缺少 specs
键。换句话说,它找不到要运行的任何测试。
我试过 include specs
into the capabilities
dictionary inside the helper itself ,但错误仍然存在。
如果使用 multiCapabilities
,如何修复错误并设置 firefox 配置文件?
作为解决方法,我创建了一个单独的 Protractor 配置文件,仅配置了 firefox(使用 capabilities
)并设置 grunt
运行 Protractor 两次 - 一次对于这个“带有配置文件的 firefox”配置,另一个用于所有其他浏览器。
最佳答案
现在,如果我们不使用多重能力, Protractor 只能接受 promise 作为能力。这样做的原因是因为 multiCapabilities 在一个新的进程中运行每个任务,所以不能传递 promise (函数)(单个功能可以工作,因为我们没有 fork )。
或者,我们可以在将已解析的功能传递到新进程之前解析启动器中的功能;然而,这将破坏设置代理的能力 ( https://github.com/angular/protractor/pull/1040 ),这依赖于在 driverProvider 设置之后解决的能力 promise 。
我想不出一个简单的方法来做到这一点(无需大量重构),但它绝对可行。 我为 Protractor 创建了一个问题 (https://github.com/angular/protractor/issues/1594)。如果这是您需要的东西或您有其他实现它的想法,请关注它和/或对其发表评论。
现在您需要使用您在原始问题中提到的解决方法。
更新
https://github.com/angular/protractor/pull/1629支持这一点。从 Protractor 1.6 开始(或者如果您同步到 master),您可以将函数传递给 config.getMultiCapabilities
,例如 onPrepare
和 onCleanup
。此函数可以返回对 multiCapabilties
的 promise (即 capabilities
数组)。
参见 https://github.com/angular/protractor/blob/master/spec/getCapabilitiesConf.js举个例子。
关于javascript - 使用 promise 配置多个功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27264146/