在 headful 模式下尝试 运行 剧作家测试时出错

Error while trying to run playwright test in headful mode

我在尝试 运行 这个简单的剧作家测试时遇到错误。在无头模式下工作正常,但在有头模式下尝试 运行 时给我带来了麻烦。我可能缺少一些依赖项??

example.spec.ts

import { test, expect } from '@playwright/test'

test('Simple test',async ({ page }) => {
    await page.goto('https://www.example.com')

})

package.json

{
  "name": "test123",
  "version": "1.0.0",
  "description": "Automated Softwre Testing",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@playwright/test": "^1.19.1",
    "prettier": "^2.5.1"
  }
}

我遇到的错误

akritishahi@LAPTOP-KM9UAVQD:~/test123$ npx playwright test --headed

Running 1 test using 1 worker

  ✘  example.spec.ts:3:1 › Simple test (156ms)


  1) example.spec.ts:3:1 › Simple test =============================================================

    browserType.launch: Browser closed.
    ==================== Browser output: ====================
    <launching> /home/akritishahi/.cache/ms-playwright/chromium-965416/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,AcceptCHFrame,AutoExpandDetailsElement --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-1w9YPx --remote-debugging-pipe --no-startup-window
    <launched> pid=10366
    [pid=10366][err] [10366:10366:0222/203334.001670:ERROR:ozone_platform_x11.cc(234)] Missing X server or $DISPLAY
    [pid=10366][err] [10366:10366:0222/203334.001780:ERROR:env.cc(225)] The platform failed to initialize.  Exiting.
    =========================== logs ===========================
    <launching> /home/akritishahi/.cache/ms-playwright/chromium-965416/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,AcceptCHFrame,AutoExpandDetailsElement --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-1w9YPx --remote-debugging-pipe --no-startup-window
    <launched> pid=10366
    [pid=10366][err] [10366:10366:0222/203334.001670:ERROR:ozone_platform_x11.cc(234)] Missing X server or $DISPLAY
    [pid=10366][err] [10366:10366:0222/203334.001780:ERROR:env.cc(225)] The platform failed to initialize.  Exiting.
    ============================================================

        at Object._baseTest.extend.browser.scope [as fn] (/home/akritishahi/test123/node_modules/@playwright/test/lib/index.js:163:51)
        at /home/akritishahi/test123/node_modules/@playwright/test/lib/fixtures.js:78:81


  1 failed
    example.spec.ts:3:1 › Simple test ==============================================================

看起来您是 linux 的 运行,没有任何 window 经理。可能 docker、wsl 或者您使用 ssh(不支持 X11(至少开箱即用))。

设置 window 管理器,或使用功能齐全的桌面 linux。