运行 WSL 赛普拉斯

Running Cypress on WSL

我正在尝试 运行 使用 Ubuntu 在 WSL 上使用 cypress,这就是我得到的结果:

$ cypress run
[29023:1018/155130.159647:ERROR:bus.cc(392)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[29023:1018/155130.162020:ERROR:bus.cc(392)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[29023:1018/155130.162068:ERROR:bus.cc(392)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[29211:1018/155130.193707:ERROR:gpu_init.cc(441)] Passthrough is not supported, GL is swiftshader

...

[29023:1018/155132.292604:ERROR:bus.cc(392)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")

Timed out waiting for the browser to connect. Retrying...
[29023:1018/155232.249036:ERROR:bus.cc(392)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")

Timed out waiting for the browser to connect. Retrying again...
[29023:1018/155332.249372:ERROR:bus.cc(392)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
 (-2) loading 'http://localhost:3000/__/#/tests/integration/simple.spec.ts'
Error:  (-2) loading 'http://localhost:3000/__/#/tests/integration/simple.spec.ts'
    at rejectAndCleanup (electron/js2c/browser_init.js:161:7486)
    at Object.failListener (electron/js2c/browser_init.js:161:7699)
    at Object.emit (events.js:376:20)

我找不到任何相关主题,有帮助吗?

Cypress 需要 运行 其 GUI 的能力。根据您的 Windows 版本,您可能需要一些额外的配置才能 运行 WSL 中的 GUI 应用程序:

  • 对于所有 Windows 版本,确保安装 required dependencies:

    apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
    

    这可能已经为您完成,具体取决于您安装 Cypress 的方式。我在 Cypress 文档中使用了 npm directions

  • Windows 11 默认包含 WSLg 功能,它允许您直接在 Windows 上 运行 GUI 应用程序。如果您从 Windows 10 升级到 Windows 11,运行 wsl --update 以确保您拥有带有 WSLg 的最新 WSL 版本。

    另外请确保,如果您尝试 运行 旧版本上的 X 服务器(如下一条建议),请确保在启动时删除 DISPLAY 的任何手动配置文件(例如 ~/.bashrc 等)。

  • 对于Windows10,您需要做一些额外的配置。实际上有两种方法可以做到这一点,但对于超级用户来说这是一个更好的主题(因为它与编程没有直接关系),所以我将向您指出 this Super User question 以了解一些细节。任何一个答案都可以。虽然我偏爱我的解决方案,但大多数人选择 运行 第三方 X 服务器,如 harrymc 在那里的回答。

只是为了确保获得 Cypress 运行ning 不需要任何“隐藏技巧”,我可以确认我能够使用 Cypress instructions 成功 ./node_modules/.bin/cypress open以及我的 xrdp 来自超级用户回答的技巧。

此错误也开始出现在我们的 Azure Cypress 管道中。然而,当我们迁移到 Cypress 8.6.0 时,它就开始发生了,当有人问到这个问题时,它是 Cypress 的最新版本。恢复到 8.4.0 解决了我们的问题。

Cypress 故障排除页面指示您可以忽略这些错误。我现在不确定这是错误还是转移注意力。

https://docs.cypress.io/guides/references/troubleshooting#Run-the-Cypress-app-by-itself

Note: verbose Electron logging might show warnings that still allow Cypress to work normally. For example, the Cypress Test Runner opens normally despite the scary output below:[475:0617/150421.326986:ERROR:bus.cc(395)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory [475:0617/150425.061526:ERROR:bus.cc(395)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix") [475:0617/150425.079819:ERROR:bus.cc(395)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")

我在超时的 cypress 运行 上遇到了这个错误,但在成功的 运行 上也遇到了这个错误。这让我相信我可以忽略它。

我看了各种帖子,运气不佳,有时在 VPN 后面,公司防火墙似乎是一个主要问题。

我经常会遇到这样的错误:

[14874:0408/102328.150664:ERROR:bus.cc(392)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[14874:0408/102328.150745:ERROR:bus.cc(392)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[15032:0408/102328.255402:ERROR:gpu_init.cc(453)] Passthrough is not supported, GL is swiftshader, ANGLE is
[14874:0408/102328.321306:ERROR:bus.cc(392)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[14874:0408/102328.331513:ERROR:bus.cc(392)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[14874:0408/102402.013363:ERROR:connection.cc(66)] X connection error received.
[15032:0408/102402.014034:ERROR:connection.cc(66)] X connection error received.
[15032:0408/102402.014064:ERROR:connection.cc(66)] X connection error received.

我发现问题是 WSL2 需要将显示设置为主机 Windows 机器的 IP 地址。这看起来很奇怪,但是如果您不熟悉 WSL2,它有自己的 IP 地址和子网;因此你需要告诉它使用不是它自己的显示器的IP。

我在这里记录了完整的过程:https://gist.github.com/pjobson/6b9fb926c59f58aa73d4efa10fe13654

我的步骤是:

  1. 安装依赖项
  2. 为我的公司防火墙安装证书
  3. 安装节点
  4. 安装 vcxsrv
  5. 设置$DISPLAY
  6. 设置DBUS
  7. 开始X-Server
  8. 编辑Windows防火墙
  9. 安装赛普拉斯