Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to bail the suite if a certain test fails?

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?

like image 601
jcollum Avatar asked Apr 23 '19 16:04

jcollum


2 Answers

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();
    })
like image 154
Alex Kamaev Avatar answered Oct 18 '22 10:10

Alex Kamaev


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

like image 36
mlosev Avatar answered Oct 18 '22 11:10

mlosev