如何从Cypress Runner及Cypress Cucumber HTML报告中隐藏已跳过的测试用例?
如何从Cypress Runner和Cucumber HTML报告中移除跳过的测试用例
一、从Cypress Runner中移除跳过的测试用例
针对带跳过标签的Cucumber场景
如果你的跳过场景是用@skip标签标记的,直接在运行Cypress时添加标签过滤参数:
cypress run --env tags="not @skip"
或者在cypress.config.js/cypress.config.ts中配置默认过滤规则,避免每次运行都加参数:
module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { const cucumber = require('cypress-cucumber-preprocessor').default; on('file:preprocessor', cucumber()); return { ...config, env: { ...config.env, tags: "not @skip" } }; }, }, });
这样Cypress会直接忽略带@skip标签的场景,不会在Runner中显示。
针对用it.skip跳过的普通测试用例
可以通过自定义钩子过滤测试用例,在setupNodeEvents中添加逻辑:
module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { on('before:run', (details) => { const fs = require('fs'); // 过滤掉包含skip标记的测试用例 details.specs = details.specs.filter(spec => { const content = fs.readFileSync(spec.relative, 'utf8'); return !content.includes('it.skip') && !content.includes('describe.skip'); }); }); }, }, });
二、从Cucumber HTML报告中移除跳过的测试用例
方法1:通过cypress-cucumber-preprocessor配置过滤
在Cypress配置中开启omitFiltered选项,确保被过滤的场景不进入报告数据:
module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { const cucumber = require('cypress-cucumber-preprocessor').default; on('file:preprocessor', cucumber()); return { ...config, cucumber: { filterSpecs: true, omitFiltered: true, tags: "not @skip" } }; }, }, });
方法2:在HTML报告生成时过滤
如果使用multiple-cucumber-html-reporter生成报告,可在报告脚本中添加状态过滤,排除skipped状态的用例:
const report = require('multiple-cucumber-html-reporter'); report.generate({ jsonDir: './cypress/cucumber-json', // 你的Cucumber JSON报告路径 reportPath: './cypress/reports/html', // HTML报告输出路径 filters: { status: ['passed', 'failed', 'pending'] // 只保留这些状态的用例,排除skipped }, displayDuration: true });
这样配置后,无论是Cypress Runner还是最终的HTML报告,都不会再显示已跳过的测试用例。
内容的提问来源于stack exchange,提问作者chanchal kumar
相关产品推荐
相关产品推荐

