我正在使用addContext()
mocha 提供的在 Mochawesome html 报告中附加失败截图。我在下面写了这个support/index.js
Cypress.on('test:after:run', (test, runnable) => {
if (test.state === 'failed') {
const screenshot = `FailureScreenshots/${Cypress.spec.name
}/${runnable.parent.title} -- ${test.title} (failed).png`;
addContext({ test }, screenshot);
}
});
当出现故障(并且没有测试重试)时,这非常有效,它只是在 html 报告中附加了故障屏幕截图,基于test.state
. 但是,在测试重试的情况下,在第一次运行时测试失败但在第二次运行时测试通过,它仍然会附加失败屏幕截图。我怎样才能防止这种情况?它应该只在重试次数用尽后测试最终失败时附加屏幕截图。