对赛普拉斯测试重试执行自定义操作
Perform custom actions on Cypress test retry
我在 Cypress 测试中使用重试。每次重试测试时,我都想执行一个操作(例如,在文件中记录有关失败的详细信息)。
我认为 the catalog of events 中的 command:retry
可能有用,但我不确定参数的含义以及如何使用它。
有一个 cyclope 插件可能涵盖了您想要对测试失败执行的操作。此插件包含一个实用函数 savePageIfTestFailed
,您可以在 support/index.js
文件中的 afterEach()
中调用它。
您可能会发现 command:retry
有点过于精细,请尝试 on fail 事件。
Cypress.on('fail', (error, runnable) => {
debugger
// take a look at the parameters
console.log('error', error.message)
console.log('runnable', runnable)
// for example
let currentTest = runnable.ctx.currentTest
let title = runnable.title
throw error // throw error to have test still fail
})
关于重试
传递给 on('fail') 事件的 运行nable 对象有几个属性提供有关重试的有用信息。
假设您在测试中设置了 {retries: 2}
,每次尝试失败都会调用失败事件。
第一个和第二个 运行, runnable.final === false
.
在第三次也是最后一次尝试时,runnable.final === true
加上 runnable.prevAttempts
有前两次(失败的)尝试的数组。
如果第三次尝试通过,我还没有检查你得到了什么。
我在 Cypress 测试中使用重试。每次重试测试时,我都想执行一个操作(例如,在文件中记录有关失败的详细信息)。
我认为 the catalog of events 中的 command:retry
可能有用,但我不确定参数的含义以及如何使用它。
有一个 cyclope 插件可能涵盖了您想要对测试失败执行的操作。此插件包含一个实用函数 savePageIfTestFailed
,您可以在 support/index.js
文件中的 afterEach()
中调用它。
您可能会发现 command:retry
有点过于精细,请尝试 on fail 事件。
Cypress.on('fail', (error, runnable) => {
debugger
// take a look at the parameters
console.log('error', error.message)
console.log('runnable', runnable)
// for example
let currentTest = runnable.ctx.currentTest
let title = runnable.title
throw error // throw error to have test still fail
})
关于重试
传递给 on('fail') 事件的 运行nable 对象有几个属性提供有关重试的有用信息。
假设您在测试中设置了 {retries: 2}
,每次尝试失败都会调用失败事件。
第一个和第二个 运行, runnable.final === false
.
在第三次也是最后一次尝试时,runnable.final === true
加上 runnable.prevAttempts
有前两次(失败的)尝试的数组。
如果第三次尝试通过,我还没有检查你得到了什么。