I want to view the output of cy.log() command in mochawesome HTML report. Below is the code
/// <reference types="cypress" />
describe("Cypress File Upload", function() {
it("File Upload test", () => {
cy.visit('https://the-internet.herokuapp.com/')
cy.get('a[href="/upload"]').click()
const file = 'example.json'
cy.get('#file-upload').click().attachFile(file)
cy.get('#file-submit').click()
cy.log(file)
cy.get('#uploaded-files').contains('example.json', {matchCase: true})
})
})
The generated HTML report shows cy.log(file) as it is although example.json is expected
How can I view the output of aforementioned command?
You can use addContext. In cypress/support/commands.js you have to put this code:
import addContext from 'mochawesome/addContext';
Cypress.Commands.add('addContext', (context) => {
cy.once('test:after:run', (test) => addContext({ test }, context));
});
After that you can use the command cy.adContext in your test:
cy.get('p').invoke('text').then(($text) => {
cy.addContext($text);
});