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

如何在Cucumber Webdriver IO中顺序运行多个Feature文件

在Cucumber WebdriverIO中依次运行多个Feature文件的方法

方法1:通过配置文件指定运行顺序

在项目根目录的wdio.conf.js中,找到specs字段,按你需要的顺序列出所有Feature文件的路径:

exports.config = {
  // 其他配置项...
  specs: [
    './features/first.feature',
    './features/second.feature',
    './features/third.feature'
  ],
  // 其他配置项...
}

保存配置后,在终端执行命令:

npx wdio run wdio.conf.js

Cucumber会严格按照你在specs数组中定义的顺序执行这三个Feature文件。

方法2:命令行直接指定顺序

如果不想修改配置文件,可直接在命令行按顺序指定Feature文件路径:

npx wdio run wdio.conf.js --spec ./features/first.feature ./features/second.feature ./features/third.feature

这种方式会临时覆盖配置文件中的specs设置,按你输入的顺序执行测试。

方法3:VS Code配置一键运行任务

  1. 按下Ctrl+Shift+B(Windows/Linux)或Cmd+Shift+B(Mac)打开任务面板,选择「创建tasks.json文件」,再选「Others」模板。
  2. 将生成的tasks.json修改为以下内容:
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run Cucumber Features in Order",
      "type": "shell",
      "command": "npx wdio run wdio.conf.js --spec ./features/first.feature ./features/second.feature ./features/third.feature",
      "group": "test",
      "problemMatcher": []
    }
  ]
}
  1. 保存后,再次打开任务面板,选择「Run Cucumber Features in Order」即可一键按顺序运行测试。

注意事项

确保wdio.conf.js中已正确配置Step Definition文件路径,否则Cucumber无法找到对应的步骤实现:

exports.config = {
  // 其他配置项...
  cucumberOpts: {
    require: ['./step-definitions/**/*.js']
  }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 20:35:31