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

如何在Playwright测试中使用多标签/注解?

Playwright 多测试标签用法指南

Playwright 官方文档只展示了单个测试标签的写法:

test('My test @foo', async ({ page }) => {
  // 测试逻辑
});

但要实现多标签,正确的写法是给每个标签都加上@前缀,用空格分隔,示例如下:

test('My test @foo @bar', async ({ page }) => {
  // 测试逻辑
});

运行指定标签的测试

  • 运行带@foo 或 @bar标签的测试:
    npx playwright test --grep "@foo|@bar"
    
  • 运行同时包含@foo 和 @bar标签的测试:
    npx playwright test --grep "@foo.*@bar"
    

你之前尝试的@foo, bar或@foo bar写法不会被识别为两个独立标签——Playwright 是通过@符号来识别每个标签的,所以每个标签都必须单独加@前缀才能被正确解析。

内容的提问来源于stack exchange,提问作者I.sh.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 06:02:33