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

执行npx playwright test时出现No tests found及EPERM权限错误,如何解决?

解决Playwright执行测试时的"No tests found"和EPERM权限错误

问题说明

执行npx playwright test时出现两个错误:找不到测试用例,同时无权限创建playwright-report目录。以下是针对性解决方案:

1. 修复"No tests found"问题

Playwright默认扫描tests目录下的*.spec.ts/*.spec.js文件,按以下步骤排查:

  • 确认工作目录:必须在C:\Users\User\PlaywrightAutomation根目录下执行测试命令,若在其他目录,需指定完整测试文件路径:
    npx playwright test C:\Users\User\PlaywrightAutomation\tests\example.spec.ts
    
  • 检查配置文件:打开playwright.config.ts,确保testDir字段指向正确的测试目录:
    export default defineConfig({
      testDir: './tests', // 验证该路径与你的测试文件目录匹配
      // 其他配置项...
    });
    
  • 核对文件名:确认测试文件后缀为.spec.ts或.spec.js,Playwright不会识别无此后缀的测试文件。

2. 解决EPERM权限错误(无法创建报告目录)

该错误源于当前用户无权限在项目根目录创建文件夹,可选以下方案:

  • 管理员权限运行终端:右键CMD/PowerShell,选择「以管理员身份运行」,再执行npx playwright test
  • 修改目录权限:右键PlaywrightAutomation文件夹 → 属性 → 安全 → 编辑 → 选中当前用户,勾选「完全控制」权限,确认后重新执行命令
  • 自定义报告目录:在命令中指定一个你有权限写入的目录生成报告:
    npx playwright test --reporter=html:./my-test-report
    
    或在playwright.config.ts中永久配置:
    export default defineConfig({
      reporter: [['html', { outputFolder: './my-test-report' }]],
      // 其他配置项...
    });
    

验证

完成以上配置后,重新执行测试命令,若测试正常运行且报告目录生成,说明问题已解决。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 01:05:13