SuperAPI AI 工具集

playwright-cucumber-expert

测试与质量

查看项目

更新于 10-16 06:20

技能介绍

用途:该技能面向使用 Cucumber BDD 与 Playwright 编写可维护端到端测试的场景,覆盖从环境搭建到 CI 集成的完整流程。

主要能力:搭建 @cucumber/cucumber + Playwright + TypeScript 环境;编写 Gherkin .feature 文件(Scenario、Outline、Background、DataTable、DocString);实现 Given/When/Then 步骤定义;用 World 类管理浏览器生命周期;编写 Before/After 与标签钩子;配置 cucumber.js 多 profile(smoke、regression、sanity);用标签表达式运行测试;配置 HTML/JSON/JUnit 报告并嵌入截图;接入 GitHub Actions。

使用方式:先确认复杂度等级(Basic/Intermediate/Advanced/Enterprise),再按等级生成目录结构与配置。可用 node scripts/scaffold-bdd.mjs --level <1-4> 生成目录;assets/ 提供可复用模板(config/cucumber.js、features/sample.feature、steps/sample.steps.ts、support/world.ts、support/hooks.ts、utils/config.ts、tsconfig/tsconfig.json)。步骤定义须用 async function (this: PlaywrightWorld),页面交互放在 Page Object 中,断言只写在 Then 步骤,Before 中启动新浏览器,After 中用 try/finally 关闭并在失败时 this.attach() 截图,每个 profile 设置 publishQuiet: true,tsconfig 使用 "module": "commonjs"。

适用场景:BDD 测试基础设施搭建、特性文件与步骤定义编写、多 profile 与标签执行、报告与 CI 集成、步骤定义与不稳定场景调试。

限制:Page Objects、选择器、命名约定与 API 测试由 playwright-automation-expert 技能覆盖,需另行加载;不可混用 @playwright/test 的 test() 运行器与 Cucumber;不得在步骤定义中使用箭头函数、在 Given/When 中加断言、硬编码 URL 或凭据、在 BeforeAll/AfterAll 访问 this.page、提交 reports/ 目录。具体安装命令与版本信息暂未提供。