2

我正在将 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 图像时会出现相同的问题。

4

1 回答 1

3

node:latest没有适当的系统依赖项来运行浏览器。您可以使用Playwright 泊坞窗图像

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

(编辑以反映官方 docker 图像)

于 2020-06-26T22:09:07.547 回答