javascript 如何,可以这么说,在每次量角器 -spec 测试后重新启动或关闭浏览器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28991395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to, so to speak, restart or close browser after every protractor -spec test
提问by Joseph Freeman
I am implementing Protractor test for a web app. I have done some google searching but I have come up with zip, I want to every spec that I create to close the browser after it has ran all of the test in that specific spec file and then continue on to the next -spec file, etc. I've things such as using "beforeAll" and "afterAll" but Jasmine doesn't recognize these methods. A point in the right direction would be awesome!
我正在为 Web 应用程序实施量角器测试。我已经做了一些谷歌搜索,但我想出了 zip,我希望我创建的每个规范在浏览器运行该特定规范文件中的所有测试后关闭浏览器,然后继续下一个 -spec 文件,等等。我有诸如使用“beforeAll”和“afterAll”之类的东西,但 Jasmine 无法识别这些方法。指向正确方向的点会很棒!
describe('i will put something more meaningful here later :)', function () {
describe('我稍后会在这里放一些更有意义的东西:)', function () {
//not sure if this method actually exist in Jasmine
afterAll(function () {
//restart browser or something of the nature
});
it('should do stuff', function () {
});
it('do stuff', function () {
});
});
});
browser should then close, and then open back up to run the next spec.
然后浏览器应该关闭,然后重新打开以运行下一个规范。
采纳答案by alecxe
Speaking about restarting browser between tests, there is a relevant configuration option:
说到在测试之间重启浏览器,有一个相关的配置选项:
// If true, protractor will restart the browser between each test.
// CAUTION: This will cause your tests to slow down drastically.
restartBrowserBetweenTests: false,
Set it to true
.
将其设置为true
。
FYI, Here is the initial feature request:
仅供参考,这是初始功能请求:
beforeAll
and afterAll
are built into jasmine-2.x
. To make them work, you need to set jasmine2
as a testing frameworkin the protractor config:
beforeAll
并afterAll
内置于jasmine-2.x
. 为了使它们工作,您需要在量角器配置中设置jasmine2
为测试框架:
exports.config = {
...
framework: 'jasmine2',
...
}
For jasmine-1.x
, there is a third-party jasmine-beforeAll
package that provides the same exact functionality.
对于jasmine-1.x
,有一个jasmine-beforeAll
提供完全相同功能的第三方包。
回答by martin770
In protractor.conf.js:
在 protractor.conf.js 中:
capabilities:{
'shardTestFiles': true,
'maxInstances': 1
}
This will open and close the browser with each .spec file, but you may lose some of the reporting capabilities from standard plugins. If shardTestFiles is false, it will open the browser, run onPrepare, run all tests serially, then close the browser.
这将使用每个 .spec 文件打开和关闭浏览器,但您可能会失去标准插件的一些报告功能。如果 shardTestFiles 为 false,它将打开浏览器,运行 onPrepare,依次运行所有测试,然后关闭浏览器。