通过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.
相关产品推荐
相关产品推荐

