Jasmine / Protractor:在beforeEach中停止测试失败 [英] Jasmine/Protractor: stop test on failure in beforeEach
问题描述
我目前正在编写测试量角器,我想知道如果在beforeEach中的某些内容失败时是否有可能取消测试执行(并返回一些有用的消息,例如前提条件失败:无法登录用户)。
I.e.我在beforeEach中有一些帮助方法登录用户,然后进行一些设置。
I am currently writing tests protractor and I was wondering if there is some possibility to cancel test execution as soon as something in the beforeEach fails (and return some useful message like "precondition failed: could not login user"). I.e. I have some helper methods in the beforeEach that login the user and then do some setup.
beforeEach:
1) login user
2) set some user properties
显然执行没有任何意义第二步,如果第一步失败(实际上它是非常有害的,因为用户被锁定,这是不好的)。我尝试在第一步添加期望,但第二步仍然执行 - >新思路。
Obviously it does not make any sense to execute the 2nd step if the first one fails (actually its quite harmful as the user gets locked which is not nice). I tried to add an "expect" as part of the 1st step, but the 2nd step was still executed -> fresh out of ideas.
推荐答案
jasmine.Env.prototype.bailFast = function() {
var env = this;
env.afterEach(function() {
if (!this.results().passed()) {
env.specFilter = function(spec) {
return false;
};
}
});
};
然后只需致电:
jasmine.getEnv().bailFast();
(功劳归于 hurrymaplelad 谁写了一个npm就是这样做,但你不需要使用它)
(credit goes to hurrymaplelad who wrote an npm that does just that, however you don't need to use it)
这篇关于Jasmine / Protractor:在beforeEach中停止测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!