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

如何在Playwright中运行指定测试组

按Playwright测试组筛选运行测试

你可以通过两种方式基于test.describe定义的测试组筛选运行测试:

方法一:直接匹配分组名称

Playwright的--grep参数支持匹配测试分组(test.describe的名称),直接在命令行执行:

npx playwright test --grep "API Test Suite"

如果需要精准匹配(避免和其他相似名称的分组冲突),可以用正则表达式限定完整匹配:

npx playwright test --grep "^API Test Suite$"

方法二:给分组添加专属标签

在test.describe的名称里自定义一个专属标签,比如@api-group,这样筛选起来更灵活:

test.describe('API Test Suite @api-group', ()=>{
  test("get users @smoke", async ({request}) => {
    //Test here
  })

  test("get countries @integration", async ({request}) => {
    //Test here
  })
});

之后就可以用这个标签筛选整个分组的测试:

npx playwright test --grep "@api-group"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 10:17:32