問(wèn)題描述
這是使用量角器設(shè)置firefox配置文件主題的后續(xù)內(nèi)容.
根據(jù)setFirefoxProfile
howto,可以使用特殊的 "helper" js 代碼 使用 firefox-profile
和 q
庫(kù)來(lái)進(jìn)行編碼火狐配置文件動(dòng)態(tài).
這對(duì)我有用,直到我嘗試使用多個(gè)瀏覽器并配置 multiCapabilities
:
exports.config = {seleniumAddress: 'http://localhost:4444/wd/hub',多能力:[{瀏覽器名稱(chēng):'chrome',眼鏡: ['footer.disabledCookies.spec.js'],鉻選項(xiàng):{首選項(xiàng):{'profile.default_content_settings.cookies':2}}},...//這里的其他功能...helper.getFirefoxProfile()},...}
使用此設(shè)置我遇到了一個(gè)錯(cuò)誤(完整的回溯 這里):p><塊引用>
規(guī)范模式與任何文件都不匹配.
據(jù)我了解,這意味著使用 firefox 配置文件的設(shè)置缺少 specs
鍵.換句話(huà)說(shuō),它找不到任何要運(yùn)行的測(cè)試.
我已嘗試將 包含 specs
到 capabilities
幫助器本身內(nèi)部的字典,但錯(cuò)誤仍然存??在.
如果使用 multiCapabilities
,如何修復(fù)錯(cuò)誤并設(shè)置 firefox 配置文件?
作為一種解決方法,我創(chuàng)建了一個(gè)單獨(dú)的量角器配置文件,僅配置了 firefox(使用 capabilities
)并將 grunt
設(shè)置為運(yùn)行量角器兩次 - 一次對(duì)于這個(gè)帶有配置文件的firefox"配置,另一個(gè)用于所有其他瀏覽器.
目前,protractor 只能在我們不使用 multicapabilities 的情況下接受 Promise 作為能力.這樣做的原因是因?yàn)?multiCapabilities 在一個(gè)新進(jìn)程中運(yùn)行每個(gè)任務(wù),所以不能傳遞承諾(函數(shù))(單個(gè)能力有效,因?yàn)槲覀儧](méi)有分叉).
或者,我們可以在啟動(dòng)器中解析功能,然后將解析的功能傳遞給新進(jìn)程;但是,這會(huì)破壞設(shè)置代理的能力(https://github.com/angular/protractor/pull/1040),它依賴(lài)于在 driverProvider 設(shè)置后解決的能力承諾.
我想不出一個(gè)簡(jiǎn)單的方法來(lái)做到這一點(diǎn)(沒(méi)有大的重構(gòu)),但它絕對(duì)是可行的.我為 Protractor 創(chuàng)建了一個(gè)問(wèn)題(https://github.com/angular/protractor/issues/1594).如果這是您需要的或者您有其他想法來(lái)實(shí)現(xiàn)它,請(qǐng)關(guān)注和/或評(píng)論它.
現(xiàn)在您需要使用您在原始問(wèn)題中提到的解決方法.
更新
https://github.com/angular/protractor/pull/1629 支持這個(gè).從量角器 1.6 開(kāi)始(或者如果您同步到 master),您可以將函數(shù)傳遞給 config.getMultiCapabilities
,例如 onPrepare
和 onCleanup
.此函數(shù)可以向 multiCapabilties
返回一個(gè)承諾(即 capabilities
數(shù)組).
參見(jiàn) 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.
這篇關(guān)于使用 Promise 配置多種功能的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!