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

通过npm脚本运行Playwright时提示“未找到测试用例”的问题

解决npm run执行Playwright测试提示“no tests found”的问题

问题核心是npm对scripts命令中的引号解析逻辑和直接在终端执行不同,导致--grep '@slow'的参数无法被Playwright正确识别。

解决办法:

  • 转义引号:修改package.json的scripts,对引号进行转义,确保参数能正确传递给Playwright:

    "scripts": {
      "test": "npx playwright test --grep \"@slow\" --workers=1"
    }
    

    或者用单引号转义:

    "scripts": {
      "test": "npx playwright test --grep \'@slow\' --workers=1"
    }
    
  • 拆分参数传递:简化scripts命令,执行时手动传递grep参数:
    先修改scripts:

    "scripts": {
      "test": "npx playwright test --workers=1"
    }
    

    然后执行:

    npm run test -- --grep '@slow'
    

    这里的--是npm用来区分自身参数和要传递给脚本的参数的标记。

验证

修改后执行npm run test,Playwright就能正确匹配带@slow标签的测试用例,不会再出现“no tests found”的错误。

内容的提问来源于stack exchange,提问作者Tadas V.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 20:37:04