How to get test result from mocha

Viewed 121

I have a test. I use wdio and mocha. And I want after test to get my test result (pass or fail) and save in some varible. How does I can do it? I red mocha documentation and find this https://mochajs.org/api/runnable but I always has undefined result. I can`t understand how I should use it?

describe('some title', () => {
  it('some title', async () => {
    const runnable = new Runnable('some title', async () => {
      expect(await (await somePage1.someProp1).getText()).equal('some text 1');
      expect(await (await SomePage2.someProp2).getText()).equal('some text 2');
    });
    
    console.log(runnable.state);
  });
});
1 Answers

You can use mochawesome for that. It's very efficient and outputs both JSON and styled elegant HTML reports.

You can install it globaly via npm

npm install -g mochawesome

And then run it

mocha --reporter mochawesome

More about mochawesome - https://github.com/adamgruber/mochawesome

Related