2

I'm doing E2E Tests on my own and I found really useful node libraries such as CodeceptJS, WebdriverIO and mocha (mochawesome).

Mochawesome permit to add images in the report but in the way that is explained in its docs with addContext https://www.npmjs.com/package/mochawesome doesn't work with CodeceptJS.

I didn't find any reference about this feature used in CodeceptJS, I only found a git request https://github.com/Codeception/CodeceptJS/issues/379

Is there a way to add images to mochawesome reported generated by mocha using CodeceptJS?

I have my file_test.js with one Before, one After and one Scenario. What I did is const addContext = require('mochawesome/addContext');

and than add the 'addContext(this,imagePath)' function but I get error

[mochawesome] Error adding context: Invalid test object.

Mitro
  • 1,179
  • 6
  • 25
  • 58

2 Answers2

1

I think the this object you're looking for is this.ctx in Codeceptjs.

Try with addContext(this.ctx, imagePath)

ricca509
  • 11
  • 1
  • Could you elaborate on this? Where dit you get this information from and what is `this.ctx` referring to? The asker mentioned he struggled with finding appropriate documentation. – aleneum Nov 22 '17 at 17:30
  • The error `[mochawesome] Error adding context: Invalid test object.` is related to the fact that the wrong `this` object is being passed into `addContext(this, imagePath)`. The test object that Codeceptjs requires is found in `this.ctx`. I have no documentation to offer on this, just personal experience having used it in the past. Hope this helps – ricca509 Nov 23 '17 at 10:07
0

Test should look like:

I.addMochawesomeContext('<screenshot path and name here>');
.......test steps

You can find more information about mocha reporting directly on Codeceptjs web-site: http://codecept.io/reports/

Btw. you cannnot add context in Before and After, context should be unique for each scenario.