问题描述
这是使用量角器设置firefox配置文件主题的后续内容.
根据setFirefoxProfile
howto,可以使用特殊的 "helper" js 代码 使用 firefox-profile
和 q
库来进行编码火狐配置文件动态.
这对我有用,直到我尝试使用多个浏览器并配置 multiCapabilities
:
exports.config = {seleniumAddress: 'http://localhost:4444/wd/hub',多能力:[{浏览器名称:'chrome',眼镜: ['footer.disabledCookies.spec.js'],铬选项:{首选项:{'profile.default_content_settings.cookies':2}}},...//这里的其他功能...helper.getFirefoxProfile()},...}
使用此设置我遇到了一个错误(完整的回溯 这里):p><块引用>
规范模式与任何文件都不匹配.
据我了解,这意味着使用 firefox 配置文件的设置缺少 specs
键.换句话说,它找不到任何要运行的测试.
我已尝试将 包含 specs
到 capabilities
帮助器本身内部的字典,但错误仍然存在.
如果使用 multiCapabilities
,如何修复错误并设置 firefox 配置文件?
作为一种解决方法,我创建了一个单独的量角器配置文件,仅配置了 firefox(使用 capabilities
)并将 grunt
设置为运行量角器两次 - 一次对于这个带有配置文件的firefox"配置,另一个用于所有其他浏览器.
目前,protractor 只能在我们不使用 multicapabilities 的情况下接受 Promise 作为能力.这样做的原因是因为 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
,例如 onPrepare
和 onCleanup
.此函数可以向 multiCapabilties
返回一个承诺(即 capabilities
数组).
参见 https://github.com/angular/protractor/blob/master/spec/以 getCapabilitiesConf.js 为例.
This is a follow-up to the Set firefox profile with protractor topic.
According to the setFirefoxProfile
howto, it is possible to set a firefox profile with a special "helper" js code which uses firefox-profile
and q
libraries to make an encoded firefox profile on the fly.
This worked for me until I've tried to use multiple browsers and configuring 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()
},
...
}
With this setup I'm getting an error (full traceback here):
Spec patterns did not match any files.
As I understand, this means that the setup with firefox profile is missing specs
key. In other words, it cannot find any tests to run.
I've tried to include specs
into the capabilities
dictionary inside the helper itself, but the error persists.
How to fix the error and set firefox profile if using multiCapabilities
?
As a workaround, I've created a separate protractor configuration file with only firefox configured (using capabilities
) and set grunt
to run protractor twice - one for this "firefox with a profile" config and the other one for all other browsers.
Right now, protractor can only accept promise as capabilities if we are NOT using multicapabilities. The reason for this is because multiCapabilities runs each task in a new process, so the promise (function) cannot be passed (single capabilities work because we're not forking).
Alternatively we could resolve capabilities in the launcher, before passing the resolved capabilities into the new processes; however, this will break the ability to set up proxies (https://github.com/angular/protractor/pull/1040), which relies on capability promises to be resolved after driverProvider setup.
I can't think of an easy way of doing this (without large refactoring), but it is definitely doable. I created an issue for Protractor (https://github.com/angular/protractor/issues/1594). Please follow that and/or comment on it if this is something you need or you have other ideas to implement it.
For now you would need to use the workaround you mentioned in your original question.
UPDATE
https://github.com/angular/protractor/pull/1629 supports this. Starting in protractor 1.6 (or if you sync to master) you can pass in a function to config.getMultiCapabilities
like onPrepare
and onCleanup
. This function can return a promise to multiCapabilties
(i.e. array of capabilities
).
See https://github.com/angular/protractor/blob/master/spec/getCapabilitiesConf.js for an example.
这篇关于使用 Promise 配置多种功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!