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

如何在Playwright集成Cucumber JS环境中运行指定Feature文件

解决Cucumber JS + TypeScript无法单独运行指定Feature文件的问题

问题根源

你的cucumber.json配置中,default配置块的paths参数指定了全局匹配规则src/features/**/*.feature,这个配置优先级高于命令行传入的单个文件路径,导致无论你命令行指定哪个文件,都会执行所有符合全局规则的Feature文件。

解决方案

方案1:临时通过命令行覆盖配置

无需修改现有配置,直接在命令行中通过参数覆盖全局paths:

  • 使用npx直接运行:
    npx cucumber-js --default.paths=src/features/content-creator.feature
    
  • 使用npm run test时,需要加--来传递参数给底层的cucumber-js:
    npm run test -- --default.paths=src/features/content-creator.feature
    

方案2:修改配置移除全局paths(推荐,更灵活)

删除cucumber.json中的paths字段,让命令行参数决定要运行的文件:
修改后的cucumber.json:

{
  "default": {
    "require": ["src/step-definations/*.ts", "src/support/hooks.ts"],
    "requireModule": ["ts-node/register"],
    "format": ["html:cucumber-report.html"],
    "publish-quite": true
  }
}

之后即可正常使用命令行指定单个文件:

  • 直接用npx:
    npx cucumber-js src/features/content-creator.feature
    
  • 通过npm script运行:
    npm run test -- src/features/content-creator.feature
    

修正你之前的错误命令

你尝试的第一个命令路径错误,你的Feature文件位于src/features目录下,而非根目录的features,正确路径应为src/features/admin.feature,但因为之前的全局paths配置覆盖,所以即使路径正确也会执行所有文件。

内容的提问来源于stack exchange,提问作者Muhammad Saad

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 09:42:19