在WSL上运行Cypress

21

我正在尝试在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)

我找不到任何相关的主题,需要帮助吗?

5个回答

16

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

  • For all Windows releases, make sure you install the required dependencies:

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

    This may have been done for you depending on how you installed Cypress. I used the npm directions in the Cypress doc.

  • Windows 11 includes the WSLg feature by default, which allows you to run GUI applications directly on Windows. If you upgraded from Windows 10 to Windows 11, run wsl --update to make sure you have the latest WSL version with WSLg.

    Also make sure, if you've attempted to run an X server on an older release (like in the next suggestion), that you remove any manual configuration of DISPLAY in your startup files (e.g. ~/.bashrc, etc.).

  • For Windows 10, you will need to do some additional configuration. There are really two ways to do this, but it's a better topic for Super User (since it isn't directly related to programming), so I'm going to point you to this Super User question for some details. Either answer there is fine. While I'm partial to my solution, most people opt for running a third-party X server as in harrymc's answer there.

为了确保没有需要使用“隐藏技巧”来运行Cypress,我可以确认我成功地使用Cypress指令和我从Super User答案中学到的xrdp技术来执行./node_modules/.bin/cypress open

2
Cypress可以在没有GUI的情况下运行。这就是OP提到的cypress run。对于cypress open,答案仍然适用。 - akauppi

9

这个错误也在我们的Azure Cypress pipeline中出现了。不过,这是在我们迁移到Cypress 8.6.0后开始发生的,这是在提问时最新的Cypress版本。回退到8.4.0版本解决了我们的问题。


2
这个问题似乎也开始在 Github Actions(据我所知,与 Azure Pipelines 使用相同的技术)中出现了。这里有一个 Github 问题跟踪此问题。 - sceee

6

由于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. 安装Node
  4. 安装vcxsrv
  5. 设置$DISPLAY
  6. 设置DBUS
  7. 启动X-Server
  8. 编辑Windows防火墙
  9. 安装Cypress

5
Cypress故障排除页面指出您可以忽略这些错误。我现在不确定这是错误还是一个误导。

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

注意:详细的 Electron 日志可能显示警告,但仍然允许 Cypress 正常工作。例如,尽管下面有可怕的输出,Cypress 测试运行器仍然正常打开:[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 运行中遇到了这个错误,但也出现在成功的运行中。这使我相信我可以忽略它。

1
今天我遇到了这个错误,更新了Cypress后,错误就解决了。
npm install cypress@latest

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接