将失败的测试列表导出到 CSV - 当您通过Cypress 模块 API运行测试时,您将在节点脚本中运行它们,并可以访问每个测试结果并 fs 将结果写出。
这是基本概念
// e2e-run-tests.js
const cypress = require('cypress')
const fs = require('fs')
cypress
.run({
// the path is relative to the current working directory
spec: './cypress/integration/**/*.spec.js',
})
.then((results) => {
console.log(results)
const tests = results.runs[0].tests
const fails = tests
.filter(test => test.state === 'failed')
.map(test => test.title.join(' - ')) // concat suite and test titles
fs.writeFileSync('failed-tests.txt', fails)
})
.catch((err) => {
console.error(err)
})
自动删除测试就像玩上膛的枪一样。
更好的是,一旦有了列表,您就可以使用cypress-select-tests防止故障再次运行
// cypress/plugins/index.js
const selectTests = require('cypress-select-tests')
const failures = require('./failed-tests.txt')
// return test names you want to run
const pickTests = (filename, foundTests, cypressConfig) => {
// found tests will be names of the tests found in "filename" spec
// it is a list of names, each name an Array of strings
// ['suite 1', 'suite 2', ..., 'test name']
return foundTests.filter(fullTestName => {
return !failures.includes(fullTestName)
})
}
module.exports = (on, config) => {
on('file:preprocessor', selectTests(config, pickTests))
}