5

I have one test that, if it fails, indicates larger problems with the app. There wouldn't be any point in running the rest of the tests if that one test fails.

Is there a way to bail the suite if a single test fails but run all tests if that test passes?

Alex Skorkin
  • 4,034
  • 3
  • 21
  • 44
jcollum
  • 36,681
  • 46
  • 162
  • 279

2 Answers2

5

I suggest you use a programming interface for this specific case. You can use the run method for the second time only if the first launch was successful. Please see the following code:

const createTestCafe = require('testcafe);
let testcafe = null;

createTestCafe('localhost', 1337, 1338)
    .then(tc => {
        testcafe = tc;
        const runner1 = testcafe.createRunner();

        return runner1
            .src(['test1'])
            .browsers('chrome')
            .run()

    })
    .then(() => {
        const runner2 = testcafe.createRunner();

        return runner2
            .browsers('chrome')
            .src(['test2'])
            .run();
    });
    .catch(err => {
        console.log(err);
        testcafe.close();
    })
Alex Kamaev
  • 4,985
  • 1
  • 10
  • 26
  • 2
    Thanks Alex. Not too surprised that I'll need to do a bit of extra work to get this special case to happen, it seemed unlikely to be supported out of the box. – jcollum Apr 26 '19 at 16:12
3

Yes, it's possible. There is an appropriate option in TestCafe - stopOnFirstFail

mlosev
  • 4,634
  • 1
  • 14
  • 27
  • 2
    No I want to stop on a *specific* fail, not the first fail. – jcollum Apr 24 '19 at 17:35
  • 1
    I suggest you use a programming interface for this for this specific case https://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/. You can use the `run` method for the second time only if the first launch was successful. – Alex Kamaev Apr 25 '19 at 08:17
  • 1
    that seems fair -- this should be a separate answer tho; iirc you work on the testcafe team so if you say that's the way it has to be done that's acceptable to me – jcollum Apr 25 '19 at 23:26