WSL2中Cypress图形界面启动失败问题求助
问题详情
在WSL2中配置Cypress后:
- 无GUI模式执行
npx cypress run运行测试完全正常 - 启动带X-server的图形界面时,执行命令
CYPRESS_BASE_URL=http://localhost:8000 npx cypress open --config-file cypress.json,出现以下错误:
[4735:0418/164505.014625:ERROR:gpu_init.cc(440)] Passthrough is not supported, GL is swiftshader
[4563:0418/164506.171450:ERROR:bus.cc(393)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[4563:0418/164506.187367:ERROR:bus.cc(393)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
修复步骤
1. 处理GPU警告(非致命)
Passthrough is not supported, GL is swiftshader是WSL2对GPU硬件加速的限制导致的警告,不影响Cypress正常运行,可直接忽略。若要消除该警告,启动时添加禁用GPU加速的环境变量:
CYPRESS_GPU_ACCELERATION=off CYPRESS_BASE_URL=http://localhost:8000 npx cypress open --config-file cypress.json
2. 解决DBus连接错误
Failed to connect to the bus是WSL2中DBus服务未正确配置导致,按以下操作修复:
- 启动DBus服务:
sudo service dbus start - 若启动失败,手动设置DBus环境变量:
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus - 重新执行Cypress启动命令即可。
3. 验证X-server配置
确保Windows端X-server(如VcXsrv、X410)已正常启动,且WSL2的DISPLAY变量配置正确:
- 检查
DISPLAY变量:echo $DISPLAY - 若变量为空,手动设置:
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
内容的提问来源于stack exchange,提问作者user2953989

