PlayWright报错‘Internal error: unable to connect to the test server’求解决
解决Playwright "Internal error: unable to connect to the test server" 报错的思路
排查网络与防火墙限制
- 检查目标机器的防火墙/杀毒软件,确认是否拦截了Playwright测试服务器的端口(默认随机分配,也可在
playwright.config.ts中指定固定端口,比如webServer.port: 3000),放行相关进程或对应端口。 - 执行
ping 127.0.0.1验证本地回环地址连通性,若不通需排查本地网络配置问题。
补全依赖与环境校验
- 运行
playwright install --with-deps,确保安装浏览器所需的所有系统级依赖包,部分机器可能因缺少底层依赖导致通信异常。 - 确认目标机器的Node.js版本符合Playwright官方要求(建议使用18.x或20.x LTS版本),版本不兼容可能引发服务器连接问题。
清理缓存与调整配置
- 删除Playwright缓存目录:Windows下路径为
%USERPROFILE%\AppData\Local\ms-playwright,手动删除后重新执行playwright install。 - 修改
playwright.config.ts,显式指定测试服务器绑定地址并禁用进程复用:export default defineConfig({ webServer: { command: 'npm run start', url: 'http://127.0.0.1:3000', reuseExistingServer: false, }, });
排查端口与进程占用
- 用
netstat -ano | findstr :<端口号>(Windows)查看指定端口是否被其他进程占用,若有则终止对应进程后重试。 - 打开任务管理器,结束所有
playwright.exe、node.exe相关残留进程,再重新启动Playwright。
内容的提问来源于stack exchange,提问作者Mark Chequer
相关产品推荐
相关产品推荐

