简体   繁体   English

如果 beforeAll 失败,如何跳过所有测试? 使用茉莉花和量角器

[英]How to skip all tests if beforeAll failed? Using Jasmine and Protractor

I need to skip all it() if beforeAll() failed, but all solutions that I found don't work - beforeAll( ) throw an error but all of it() still executes and gets marked as 'failed'如果beforeAll()失败,我需要跳过所有it() ,但我发现的所有解决方案都不起作用 - beforeAll( ) 抛出错误,但所有it()仍然执行并被标记为'failed'

I've tried: stopSpecOnExpectationFailure: true, and Jasmine pending() option but those still do not work.我已经尝试过: stopSpecOnExpectationFailure: true,和 Jasmine pending()选项,但这些仍然不起作用。

Does this solution fits your needs?该解决方案是否符合您的需求?

https://www.npmjs.com/package/protractor-fail-fast https://www.npmjs.com/package/protractor-fail-fast

or要么

https://github.com/pmowrer/jasmine-fail-fast https://github.com/pmowrer/jasmine-fail-fast

I know that suggest npm-packages is not a real 'answer' but I've been seeing this type of questions every couple of months and it usually ends up with using some ready and working solution (like above)我知道 suggest npm-packages 不是一个真正的“答案”,但我每隔几个月就会看到这类问题,而且通常最终会使用一些现成且有效的解决方案(如上)

Update: I will appreciate if you will come up with your own solution and share it更新:如果您能提出自己的解决方案并分享,我将不胜感激

Update 2: Also I will share one wacky way you can do it.更新 2:我还将分享一种古怪的方法。

You will need Protractor 6 (because it uses latest jasmine version)您将需要 Protractor 6(因为它使用最新的 jasmine 版本)

Let's say you tests are depending on the presences of some element.假设您的测试取决于某些元素的存在。 You can do this in your beforeAll :您可以在beforeAll中执行此操作:

let elementIsPresent = await myElement.isDisplayed()
it('should test if element is present', function() {
   if(elementIsPresent) {
      // do your thing
   } else {
    pending('skipping test')
  }
});

You need to be aware of a couple of thing:您需要注意以下几点:

  • Protractor below version 6 will mark this test as 'failed' (instead skipping)版本 6 以下的 Protractor 会将此测试标记为“失败”(而不是跳过)

  • I can not use arrow functions in your it blocks我不能在你的it块中使用箭头函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM