0

My test suite contains several 'it' sections within the 'describe'.

If one of the 'it' sections fails (e.g. if it can't find an element) - it jumps straight to the next 'it' section and carries on the test.

If an 'it' section fails I just want the test to stop running and be marked as a fail.

How do you do this?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Matt
  • 773
  • 2
  • 15
  • 30
  • That's what's *supposed* to happen. The `describe` defines a suite of related *but separate* tests, if they actually depend on one another (i.e. need to be run in a particular order) they should be a single `it` spec. – jonrsharpe Sep 21 '20 at 13:36
  • Jasmine has an option to stop immediately after a fail: https://stackoverflow.com/a/31809311/9741277 – leun4m Sep 21 '20 at 13:36
  • @jonrsharpe. That makes sense. Unfortunately I have inherited these tests. The 'it' sections are used as paragraphs to make the test more readable. Is there anyway I can cause the failure of one of the 'its' to end the whole 'describe'. Basically if an element is not found I want the whole suite to stop running. – Matt Sep 21 '20 at 13:43
  • @leun4m Thanks but I am using Mocha – Matt Sep 21 '20 at 14:04
  • 1
    Well then this might be what you are searching for (the `bail`-flag) https://stackoverflow.com/a/13959934/9741277 – leun4m Sep 21 '20 at 14:07
  • Perfect thanks @leun4m – Matt Sep 21 '20 at 14:35
  • Does this answer your question? [Skip subsequent Mocha tests from spec if one fails](https://stackoverflow.com/questions/13954531/skip-subsequent-mocha-tests-from-spec-if-one-fails) – jonrsharpe Sep 22 '20 at 08:59

1 Answers1

2

The solution to this was to use the bail flag within the mochaOpts section of wdio.conf as shown here:

mochaOpts: {
    bail: true
},

Thanks to @leun4m for this answer

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Matt
  • 773
  • 2
  • 15
  • 30
  • WebdriverIO has a 'bail' option as well (https://webdriver.io/docs/options.html#bail). But it does note that some extra configuration may be needed, which is where this answer might be best. – Kevin Lamping Sep 22 '20 at 16:16