在 GitLab 上使用 Playwright 时出现 WebSocket 错误 CI

WebSocket error when using Playwright on GitLab CI

我将 Playwright 与 Jest 和 jest-playwright-preset 一起使用,并尝试在 GitLab CI.

中进行测试 运行

我的.gitlab-ci.yml:

ui_test:
  image: node:latest
  script:
    - npm install
    - npm run test:ui

当我 运行 在我的 Windows 机器上本地运行时,一切正常。但是,如果我尝试在 GitLab CI 中 运行 我会收到以下错误:

 2020-06-26T21:01:39.770Z pw:api => chromium.launchServer started
 2020-06-26T21:01:39.786Z pw:api <= chromium.launchServer succeeded
 2020-06-26T21:01:40.182Z pw:api => chromium.connect started
 2020-06-26T21:01:40.217Z pw:api <= chromium.connect failed
 FAIL browser: chromium ./test.js
   ● Test suite failed to run
     WebSocket error: connect ECONNRESET 127.0.0.1:38267
     ================== chromium.connect logs ==================
     <ws connecting> ws://127.0.0.1:38267/b32ed779b7c87222e0b2b6aa117b0c79
     <ws connect error> ws://127.0.0.1:38267/b32ed779b7c87222e0b2b6aa117b0c79 connect ECONNRESET 127.0.0.1:38267
     <ws disconnected> ws://127.0.0.1:38267/b32ed779b7c87222e0b2b6aa117b0c79
     ============================================================
     Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.
       at WebSocket.<anonymous> (node_modules/playwright/lib/transport.js:119:24)
       at WebSocket.onError (node_modules/playwright/node_modules/ws/lib/event-target.js:128:16)
       at ClientRequest.<anonymous> (node_modules/playwright/node_modules/ws/lib/websocket.js:568:15)

编辑:这与 Jest 无关。仅使用Playwright和使用节点图像而不是Playwright图像时也会出现同样的问题。

node:latest 对 运行 浏览器没有适当的系统依赖性。您可以使用 Playwright docker image.

ui-test:
  stage: test
  image: mcr.microsoft.com/playwright:bionic
  script:
    - npm install # this should install playwright
    - npm run test:ui

(已编辑以反映官方 docker 图片)