0

I am trying to get data about single test in Cypress like title, state etc so I can create custom reporter. But none of the below options in forEach are working. It returns undefined, but when I pass normal string like 'abcd' it gets printed on console. So how do i get attributes of the test.

first.spec.js

/// <reference types="cypress" />
  context('Actions', () => {
  
  afterEach(()=> {
    const testData = cy.state('runnable').currentTest;
      cy.task('testOutput', {title: testData.title, state: testData.state, fullTitle: testData.fullTitle()});

     // also tried 

   // Cypress.on('test:after:run', (test, runnable)=> {
    //cy.task('testOutput', {title: runnable.title, state:runnable.state, fullTitle: runnable.fullTitle()});
   //)};
  });

  it('test 1',()=>{
   
    const assets = Cypress.env('assetoverride');
    cy.getVar(assets);
  })
});

plugin/index.js

module.exports = (on, config) => {
  on('task', {
    testOutput({title, state, fullTitle}){
      console.log(`Test ${fullTitle} - ${state} - ${title}`)
      return null;
    }
  });
}
pk786
  • 2,140
  • 3
  • 18
  • 24

1 Answers1

-1

If you are executing your tests localy you can run them in hedless mode by running command:

npx cypress run --spec "e2e/integration/NameOfYourTestFile.spec.js" --browser chrome --headless

This way you will get table with results in the terminal: enter image description here