0

I use WebdriverIO for E2E testing with mocha framework

When I run tests, I want that after the first error, all subsequent checks in this test were skipped, and Mocha went to the next test file

as an example, I showed the code below which needs to be taken out from each test file and applied globally.


I need to move beforeEach and afterEach from spec to global config WDIO [mocha, hook, wdio]

I need to move code from spec to global config WDIO

The main goal is to skip the tests after though the test in it has failed

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);
    });
});
IAfanasov
  • 4,775
  • 3
  • 27
  • 42

1 Answers1

1

Are you looking for bail(mocha doc)?

Once a test within a spec fails, exit the spec.

FYI: add next time your WDIO version.

Benedikt Kromer
  • 711
  • 6
  • 22
  • (Don't forget to ▲ Upvote answers that are helpful and to ✓+▲ Accept and Upvote an answer that helped you solve your problem!) – Benedikt Kromer Jul 14 '21 at 11:17