webdriverio-boneyard / wdio-mocha-framework

A WebdriverIO v4 plugin. Adapter for Mocha testing framework.
MIT License
39 stars 30 forks source link

Access to the mocha test context inside hooks #139

Open alecf opened 6 years ago

alecf commented 6 years ago

In the beforeTest/afterTest hooks, the first parameter passed (named test in the docs) is an object that looks a lot like the this.currentTest object that you normally have access to, but it is missing some parts that are useful.

For instance in mocha you can write

afterEach(function() {
   console.log('just finished ', this.currentTest.fullTitle());
});

But in the wdio-mocha-framework hook afterTest, it looks like

afterTest(test) {
   console.log('just finished ', test.fullTitle);
}

But it would be nice to just have access to the actual mocha test here.

My specific use case is that I want to report an error to mocha. (I'm using a tool called Applitools Eyes that does screenshot testing) My existing afterEach() looks like:

afterEach(function() => {
    try {
        // This can fail
        eyes.close();
    } catch(ex) {
      // report the error for this test, but do not bail on the whole suite
      this.test.error(ex)
    }
};

but this is impossible with the wdio afterTest hook, because there is no equivalent of this.test.error