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

取消Playwright配置webserver段后Windows下出现“No tests”问题

Angular + Playwright 测试异常问题(仅Windows系统)

仅Windows系统会触发该问题,Ubuntu系统可正常运行。

给Angular应用配置Playwright测试时遇到如下异常:

  • 当playwright.config.ts中默认注释的webserver配置段保持注释状态时,Playwright能正常识别并执行测试;
  • 取消该配置段注释,将URL修改为Angular默认的4200端口后,执行npx playwright test --ui会卡顿约半分钟,最终显示“No tests”。

复现步骤

  • 执行ng new angular_e2e创建新Angular项目
  • 执行npm init playwright@latest初始化Playwright
  • 运行npx playwright test --ui,可正常打开Playwright UI并显示示例测试
  • 编辑playwright.config.ts,取消webserver配置段的注释,将url字段改为http://localhost:4200
  • 再次运行npx playwright test --ui,卡顿半分钟后显示“No tests”

解决方法

  1. 修正webserver启动命令
    默认的webserver配置中command可能未匹配Angular的启动命令,需将其设置为npm run start或直接ng serve,同时确保端口与URL一致:
webserver: {
  command: 'npm run start',
  url: 'http://localhost:4200',
  reuseExistingServer: !process.env.CI,
}
  1. 排查端口占用
    用命令netstat -ano | findstr :4200检查4200端口是否被其他进程占用,若有则终止对应进程,或修改Angular启动端口。

  2. 延长webserver超时时间
    Angular项目首次启动可能较慢,可在webserver配置中添加超时设置,避免因启动超时导致测试无法被识别:

webserver: {
  command: 'npm run start',
  url: 'http://localhost:4200',
  timeout: 120000, // 延长至120秒
  reuseExistingServer: !process.env.CI,
}
  1. 确认测试文件路径配置
    检查playwright.config.ts中的testDir字段,确保其指向存放测试文件的目录(默认是tests/),若测试文件放在其他目录需同步修改该配置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 14:35:01