Detailed Reporting Cypress/Mochawesome

拥有回忆 提交于 2019-12-04 12:49:04

After much hacking about, I found a way to use Mochawesome addContext in Cypress.

Note, you can only make one addContext call per test (this is a Mochawesome limitation).

describe('DBM Smoketests', function() {
  it('E2E Hotel2 WorldPay System', function() {
    cy.visit('https://obmng.dbm.guestline.net/');
    cy.url().should('include','/obmng.dbm');

    Cypress.on('test:after:run', (test) => {
      addContext({ test }, { 
        title: 'This is my context title', 
        value: 'This is my context value'
      })
    });
  });
});

The second param is the context to be attached to the test, and it must have non-empty title and a value properties.

What you get in the mochawesome.json output is

...
"suites": [
  {
    ...
    "tests": [
      {
        "title": "E2E Hotel2 WorldPay System",
        ...
        "context": "{\n  \"title\": \"This is my context title\",\n  \"value\": \"This is my context value\"\n}",
        "code": "...",
        ...
      }
    ],

In mochawesome.html, on clicking the test you get

Additional Test Context
This is my context title:
This is my context value

I have not tried it out with value types other than string.

Note for anyone starting out with Mochawesome in Cypress, it looks like you can only get a Mochawesome report with running cypress run, not with cypress open - although there may be a way around this using mocha's multiple reporter functionality.

Yes confirmed work! It's possible to call once in each test like this:

it('Should shine the test report!!!', () => {
  cy.get('li').should('have.length.greaterThan', 0);
  addTestContext('String','giphy');
  addTestContext('Link','https://giphy.com');
  addTestContext('Image','https://media.giphy.com/media/tIIdsiWAaBNYY/giphy.gif');
  addTestContext('Image','https://media.giphy.com/media/tIIdsiWAaBNYY/giphy.gif');
});

function addTestContext(title, value) {
  cy.once('test:after:run', test => addContext({ test }, { title, value }));
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!