0

我正在尝试获取有关赛普拉斯中单个测试的数据,例如标题、状态等,以便我可以创建自定义报告器。但是 forEach 中的以下选项都不起作用。它返回未定义,但是当我传递像“abcd”这样的普通字符串时,它会打印在控制台上。那么我如何获得测试的属性。

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);
  })
});

插件/index.js

module.exports = (on, config) => {
  on('task', {
    testOutput({title, state, fullTitle}){
      console.log(`Test ${fullTitle} - ${state} - ${title}`)
      return null;
    }
  });
}
4

1 回答 1

-1

如果您在本地执行测试,您可以通过运行命令以无忧模式运行它们:

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

这样,您将在终端中获得带有结果的表格: 在此处输入图像描述

于 2021-12-16T15:38:20.973 回答