Amn*_*mna 6 html javascript cypress mochawesome
我想在 mochawesome HTML 报告中查看 cy.log() 命令的输出。下面是代码
/// <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})
})
})
Run Code Online (Sandbox Code Playgroud)
生成的 HTML 报告按原样显示 cy.log(file),尽管需要 example.json
如何查看上述命令的输出?
小智 3
您可以使用addContext。在cypress/support/commands.js中,您必须放置以下代码:
import addContext from 'mochawesome/addContext';
Cypress.Commands.add('addContext', (context) => {
cy.once('test:after:run', (test) => addContext({ test }, context));
});
Run Code Online (Sandbox Code Playgroud)
之后,您可以在测试中使用命令cy.adContext :
cy.get('p').invoke('text').then(($text) => {
cy.addContext($text);
});
Run Code Online (Sandbox Code Playgroud)