Skip to content
This repository was archived by the owner on Dec 18, 2019. It is now read-only.
This repository was archived by the owner on Dec 18, 2019. It is now read-only.

Access to the mocha test context inside hooks #139

@alecf

Description

@alecf

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions