Is there a way to skip all tests in a suite if a certain conditions fail? I.e) if the webpage is not opening, there is no point in running the rest of the tests, because they all depend on the webpage opening before any tests are run.
We can use pending() to skip the current test, but is there a way to skip all the tests in the suite or tests below right away if all the other tests depend on checkCondition to be true?
I tried adding pending() inside the beforeAll block, to try to skip all the tests since beforeAll is run before anything.
Please help! I am using WebdriverIO and Jasmine. Thank you!
let checkCondition = false;
describe(`My Test Suite`, () => {
beforeAll(async () => {
// EDIT - returnBoolean() is another method that logs into the
// page and returns true or false
let setCheckCondition = returnBoolean();
if (setCheckCondition) {
checkCondition = true;
console.log(`in true block`);
} else {
console.log('Skip tests below'); // HELP <-- since checkCondition is false, all tests below should fail
pending();
}
});
it(`Test 1`, () => {
if (checkCondition != undefined) {
console.log("checkCOndition is defined")
} else {
pending();
}
});
it(`Test 2`, () => {
if (checkCondition) {
// check
} else {
console.log('Skip this test');
pending();
}
});
it(`Test 3`, () => {
console.log("skip this test too")
});
});
If you have to set
checkCondition
inbeforeAll
and then eventually abort from there, there seems to be an ongoing issue about it on github (https://github.com/jasmine/jasmine/issues/1533)Otherwise if
checkConditon
can be known before the test suite begins (I don't see why not) you can just just replace yourbeforeAll
with something likeOr just skip the whole call to
describe
in the first placeEDIT: You can skip the whole test suite like that: