My E2E testing setup involves using the WebdriverIO library along with the mocha framework.
During test execution, I want Mocha to automatically skip all subsequent checks in a test after encountering the first error, and proceed to the next test file.
To achieve this, I have included an example code snippet below that needs to be extracted from each test file and implemented globally.
The task at hand is to transfer the beforeEach and afterEach hooks from individual spec files to the global configuration in WDIO [mocha, hook, wdio].
This transition will ensure that tests are skipped if a failure occurs within them.
import { expect } from 'chai';
describe('Verify next it is skipped', function () {
let skipNextIt = false;
beforeEach(function () {
if (skipNextIt) {
this.skip();
}
});
afterEach(function() {
if(this.currentTest.state === 'failed') {
skipNextIt = true;
}
});
it('is should pass', function () {
expect(true).to.equal(true);
});
it('is should fail', function () {
expect(true).to.equal(false);
});
it('is should skipp 1', function () {
expect(true).to.equal(true);
});
it('is should skipp 2', function () {
expect(true).to.equal(true);
});
});