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

Windows环境下Playwright+TS+Cucumber步骤未关联问题求助

Windows下Playwright+TypeScript+Cucumber.js步骤匹配失效问题排查

系统信息

  • 操作系统:Windows
  • Cucumber.js版本:^10.9.0
  • Playwright版本:^1.48.1

依赖配置

{
  "description": "",
  "dependencies": {
    "@cucumber/cucumber": "^10.9.0",
    "@types/node": "^20.16.13",
    "dotenv": "^16.4.5",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.3"
  },
  "devDependencies": {
    "@playwright/test": "^1.48.1",
    "@types/cucumber": "^7.0.0",
    "open": "^10.1.0"
  }
}

配置文件

cucumberConfig.js

/**
 * @module cucumberConfig
 */
module.exports = {
  default: {
    requireModule: ['ts-node/register'],
    require: ['./steps/**/*.ts', './hooks/**/*.ts', './features/**/*.feature'],
    format: ['progress-bar', 'html:test-reports/cucumber-report.html'],
    formatOptions: { snippetInterface: 'async-await' },
  },
};

settings.json

{
  "files.autoSave": "afterDelay",
  "editor.fontSize": 20,
  "code-runner.clearPreviousOutput": true,
  "tabnine.experimentalAutoImports": true,
  "window.menuBarVisibility": "compact",
  "cucumberautocomplete.steps": "steps/**/*.js",
  "cucumberautocomplete.syncfeatures": "features/**/*.features.js"
}

问题现象

配置如上,但feature文件中的Gherkin步骤无法关联到步骤定义,运行测试时出现Undefined step错误,VS Code中Cucumber步骤自动补全功能失效。

已尝试解决措施

  • 确认require和cucumberautocomplete.steps的文件路径与实际项目目录结构一致
  • 在settings.json中直接添加了ts扩展名
  • 重启VS Code并重新加载工作区

请求帮助

请帮忙识别配置中的错误,或提供Windows环境下Playwright+TypeScript+Cucumber.js的可用配置示例。

已确认cucumberConfig.js和settings.json中的路径均正确匹配项目目录结构:

  • cucumberConfig.js中的require路径('./steps//*.ts', './hooks//.ts', './features/**/.feature')指向了步骤定义、钩子和feature文件的正确目录
  • settings.json中的cucumberautocomplete.steps和cucumberautocomplete.syncfeatures选项也符合预期目录结构

原本期望该配置能实现feature文件中Gherkin步骤与定义的关联。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 17:45:02