javascript 如何阻止量角器在失败时运行进一步的测试用例?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28893436/
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 stop protractor from running further testcases on failure?
提问by Aman Gupta
Is there a way of quitting test suite and stop executing further test cases, if a test case fails in protractor?
如果测试用例在量角器中失败,有没有办法退出测试套件并停止执行进一步的测试用例?
采纳答案by alecxe
In case of jasmine
testing framework, you are not the first asking about it.
在jasmine
测试框架的情况下,您不是第一个询问它的人。
There are relevant open discussions/issues on exiting after a first failure, --fail-fast
option:
第一次失败后退出有相关的公开讨论/问题,--fail-fast
选项:
Long story short, this is an open issue and some day jasmine
would have the functionality built-in. Currently, use a third-party jasmine-bail-fast
module.
长话短说,这是一个悬而未决的问题,总有一天jasmine
会内置该功能。目前,使用第三方jasmine-bail-fast
模块。
Aside from that, there is a handy realtimeFailure
jasmine setting. If you set it to true
it would not fail the whole test run, but it would show errors in a real time - immediately after happening - this can possibly cover your use case. Set it in jasmineNodeOpts
:
除此之外,还有一个方便的realtimeFailure
茉莉花设置。如果您将其设置为true
它不会使整个测试运行失败,但它会实时显示错误 - 发生后立即 - 这可能涵盖您的用例。将其设置为jasmineNodeOpts
:
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
...
jasmineNodeOpts: {
realtimeFailure: true
}
}
回答by Linh Pham
jasmine-bail-fast
didn't work in my case. Not sure if it was because of some conflicts with my other report plugins.
jasmine-bail-fast
在我的情况下不起作用。不确定是否是因为与我的其他报告插件存在冲突。
In case anyone is having the same problem. You can try protractor-fast-fail
如果有人遇到同样的问题。您可以尝试量角器快速失败
import failFast from 'protractor-fail-fast';
exports.config = {
// if import statement doesn't work, use this instead of import for older versions of node
// plugins: [{
// package: 'protractor-fail-fast'
// }],
onPrepare: function() {
jasmine.getEnv().addReporter(failFast.init());
},
afterLaunch: function() {
failFast.clean();
}
}
Worked perfectly well for me.
对我来说效果很好。
EDIT: added import statement in code snippet to reflect readme of projactor-fast-fail
编辑:在代码片段中添加了 import 语句以反映 projactor-fast-fail 的自述文件
回答by Daniel Schwab
Here is my solution to skip tests on first fail with Jasmine 2 and Protractor. Hope it helps.
这是我在 Jasmine 2 和量角器首次失败时跳过测试的解决方案。希望能帮助到你。
exports.config = {
onPrepare: function () {
//skip tests after first fail
var specs = [];
var orgSpecFilter = jasmine.getEnv().specFilter;
jasmine.getEnv().specFilter = function (spec) {
specs.push(spec);
return orgSpecFilter(spec);
};
jasmine.getEnv().addReporter(new function () {
this.specDone = function (result) {
if (result.failedExpectations.length > 0) {
specs.forEach(function (spec) {
spec.disable()
});
}
};
});
}
};
回答by Andrew Drizgolovich
you don't need all those third party plugins. Use native process.exit()
.
您不需要所有这些第三方插件。使用本机process.exit()
.
Code example:
代码示例:
it("test", function()
{
...
if(isExit)
{
browser.driver.close().then(function()
{
process.exit(1);
});
}
});
profit.
利润。