我正在为Web应用程序实施Protractor测试。我已经做了一些谷歌搜索,但我已经提出了zip,我希望我创建的每个规范关闭浏览器后,它在该特定的spec文件中运行所有测试,然后继续到下一个-spec文件,我使用“beforeAll”和“afterAll”之类的东西,但Jasmine不承认这些方法。正确方向上的一点会很棒!
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 () {
});
});
浏览器应该关闭,然后打开备份以运行下一个规范。
谈到在测试之间重新启动浏览器,有一个相关的配置选项:
// If true, protractor will restart the browser between each test.
// CAUTION: This will cause your tests to slow down drastically.
restartBrowserBetweenTests: false,
将其设置为 true
。
仅供参考,这是最初的功能要求:
beforeAll
和 afterAll
内置于 jasmine-2.x
。要使它们工作,您需要设置 jasmine2
作为测试框架 在里面 量角器配置:
exports.config = {
...
framework: 'jasmine2',
...
}
对于 jasmine-1.x
,有一个第三方 jasmine-beforeAll
包提供相同的功能。
在protractor.conf.js中:
capabilities:{
'shardTestFiles': true,
'maxInstances': 1
}
这将使用每个.spec文件打开和关闭浏览器,但您可能会丢失标准插件的一些报告功能。如果shardTestFiles为false,它将打开浏览器,运行onPrepare,串行运行所有测试,然后关闭浏览器。