0

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

例子.spec.ts

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

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

})

包.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 ==============================================================
4

1 回答 1

0

看起来您在没有任何窗口管理器的情况下在 linux 上运行。可能是 docker、wsl 或者您使用 ssh(不支持 X11(至少开箱即用))。

设置一个窗口管理器,或者使用一个成熟的桌面 linux。

于 2022-02-22T13:34:41.583 回答