You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cypress如何从HTML测试报告中移除Pending与Skipped状态用例

移除报告中Pending、Skipped状态用例的落地方案

针对你用的两款报告工具,分别按以下方式处理即可:

Mochawesome 报告配置

这个工具原生支持隐藏两类状态用例,不需要额外写脚本:

  • 如果你是直接在Cypress配置里生成报告,直接在reporterOptions里加两个配置项即可,原有配置全部保留:
// cypress.config.js
reporter: 'cypress-mochawesome-reporter',
reporterOptions: {
  // 原有配置比如reportDir、overwrite、charts等不动
  showPending: false, // 不展示Pending状态用例
  showSkipped: false, // 不展示Skipped状态用例
  embeddedScreenshots: true,
  inlineAssets: true
}
  • 如果你是先导出json结果再合并生成HTML报告,在执行marge生成报告的命令里加对应参数即可:
# 合并结果步骤不变
npx mochawesome-merge cypress/reports/*.json > merged-report.json
# 生成报告时追加过滤参数
npx marge merged-report.json --showPending false --showSkipped false

配置完重新跑测试生成报告,这两类用例就不会出现在HTML里了。

Allure 报告处理

Allure本身没有提供直接的配置项隐藏这类用例,推荐两种方案,优先选第一种:

  • 方案1:从根源避免Pending用例生成
    你现在用cypress-tags做标签过滤的逻辑是先加载所有用例,运行时再跳过不匹配的,所以才会产生Pending记录。换成cypress-cucumber-preprocessor原生的标签过滤能力,不匹配标签的用例根本不会被加载到测试队列,自然不会出现在任何报告里。
    只需要在cypress配置的env节点下加cucumber过滤规则:
    env: {
      TAGS: 'not @ignore and @bdd',
      allure: true,
      cucumber: {
        filter: {
          tags: 'not @ignore and @bdd'
        }
      }
    }
    
    之后执行测试不需要再调用cypress-tags,直接跑cypress原生命令即可:
    ./node_modules/.bin/cypress run
    
    这个方案最干净,还能避免统计错误的用例总数、测试通过率。
  • 方案2:生成报告前清理无效结果
    如果不想改现有执行逻辑,就在生成Allure报告前写个简单脚本,删掉allure-results目录里状态为pending、skipped的用例结果文件,再生成报告即可。
    新建过滤脚本filter-allure.js:
    const fs = require('fs');
    const path = require('path');
    const resultDir = path.resolve(__dirname, './allure-results');
    fs.readdirSync(resultDir).forEach(file => {
      if (!file.endsWith('.json')) return;
      const fileContent = JSON.parse(fs.readFileSync(path.join(resultDir, file)));
      if (['pending', 'skipped'].includes(fileContent.status)) {
        fs.unlinkSync(path.join(resultDir, file));
      }
    });
    
    把脚本加到package.json的执行流程里,在生成报告前执行:
    {
      "scripts": {
        "test": "cypress-tags run -e TAGS='not @ignore and @bdd',allure=true test:all",
        "filter:allure": "node filter-allure.js",
        "report:allure": "npm run filter:allure && allure generate allure-results --clean -o allure-report"
      }
    }
    

注意:如果用方案2,记得每次跑测试前清空allure-results目录,避免上一次测试的残留结果影响本次报告。

内容的提问来源于stack exchange,提问作者Heera Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 15:18:13