d_kas
d_kas

Reputation: 1

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'

I've tried:stopSpecOnExpectationFailure: true, and Jasmine pending() option but those still do not work.

Upvotes: 0

Views: 1136

Answers (1)

Yuriy Gerasimovich
Yuriy Gerasimovich

Reputation: 424

Does this solution fits your needs?

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

or

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)

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.

You will need Protractor 6 (because it uses latest jasmine version)

Let's say you tests are depending on the presences of some element. You can do this in your 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)

  • I can not use arrow functions in your it blocks

Upvotes: 2

Related Questions