如何配置Allure Cypress使其仅展示Cucumber步骤而非Cypress命令?
解决Cucumber步骤在Allure报告中不显示的问题
核心配置调整
1. 锁定兼容的依赖版本
部分版本组合存在兼容性问题,建议使用以下稳定版本:
{ "dependencies": { "cypress": "^13.0.0", "cypress-cucumber-preprocessor": "^18.0.0", "allure-cypress": "^2.12.0" } }
2. 修正cypress.config.js配置
需确保cucumber预处理器与allure配置正确关联,重点在setupNodeEvents中完成插件注册与参数配置:
const { defineConfig } = require("cypress"); const createBundler = require("@bahmutov/cypress-esbuild-preprocessor"); const { addCucumberPreprocessorPlugin } = require("@badeball/cypress-cucumber-preprocessor"); const { createEsbuildPlugin } = require("@badeball/cypress-cucumber-preprocessor/esbuild"); const allureWriter = require("allure-cypress/writer"); module.exports = defineConfig({ e2e: { specPattern: "cypress/e2e/**/*.feature", async setupNodeEvents(on, config) { const bundler = createBundler({ plugins: [createEsbuildPlugin(config)], }); on("file:preprocessor", bundler); await addCucumberPreprocessorPlugin(on, config); allureWriter(on, { cucumber: true, includeCypressCommands: false, stepsOnly: true }); return config; }, }, });
3. 调整package.json脚本
确保测试执行与报告生成命令指向正确目录:
{ "scripts": { "test": "cypress run", "allure:generate": "allure generate allure-results -o allure-report --clean", "allure:open": "allure open allure-report" } }
额外排查项
- 确认feature文件与step定义文件路径匹配,cucumber预处理器可正确识别步骤实现
- 执行测试前删除旧的
allure-results目录,避免缓存干扰 - 确保全局安装allure命令行工具:
npm install -g allure-commandline
内容的提问来源于stack exchange,提问作者Leech76
相关产品推荐
相关产品推荐

