[microsoft/playwright][BUG] 关闭环境时测试超时

2024-06-25 350 views
5

代码片段

  test('example test', async ({ page }) => {
    await page.goto(<MY_URL>); // can share the url privately
  });
// config.js
 use: {
    headless: true,
    trace: 'retain-on-failure',
    screenshot: 'on',
  },
  projects: [
    {
      name: 'Desktop Chrome',
      use: { ...devices['Desktop Chrome'] },
    },
  ]

描述错误 导航到 MY_URL 超时并报告以下错误: Timeout of 20000ms exceeded while shutting down environment

浏览器日志:

 pw:browser <launching> /Users/test/Library/Caches/ms-playwright/chromium-978106/chrome-mac/Chromium.app/Contents/MacOS/Chromium --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 --enable-use-zoom-for-dsf=false --no-sandbox --user-data-dir=/var/folders/z0/5n6p2nrn1p7_q6x11nb1ck1m0000gq/T/playwright_chromiumdev_profile-zUHo3B --remote-debugging-pipe --no-startup-window +0ms
  pw:browser <launched> pid=23926 +7ms
  pw:browser [pid=23926][err] [23926:68355:0321/104018.011736:ERROR:cert_verify_proc_builtin.cc(681)] CertVerifyProcBuiltin for tags.knewz.com failed: +6s
  pw:browser [pid=23926][err] ----- Certificate i=0 (CN=tags.knewz.com) ----- +0ms
  pw:browser [pid=23926][err] ERROR: Time is after notAfter +0ms
  pw:browser [pid=23926][err]  +0ms
  pw:browser [pid=23926][err]  +0ms
  pw:browser [pid=23926][err] [23926:51715:0321/104018.011955:ERROR:ssl_client_socket_impl.cc(996)] handshake failed; returned -1, SSL error code 1, net_error -201 +0ms
  pw:browser [pid=23926][err] [23989:259:0321/104026.452691:ERROR:system_services.cc(31)] SetApplicationIsDaemon: Error Domain=NSOSStatusErrorDomain Code=-50 "paramErr: error in user parameter list" (-50) +8s
  pw:browser [pid=23926][err] 2022-03-21 10:40:31.443 Chromium Helper[23989:567532] In -[NSApplication(NSQuietSafeQuit) _updateCanQuitQuietlyAndSafely], _LSSetApplicationInformationItem(NSCanQuitQuietlyAndSafely) returned error -50 +

回答

4

@Nav-2dTimeout of 20000ms exceeded while shutting down environment表示清理不起作用,很可能关闭了页面或浏览器。以下几个问题有助于诊断问题:

  • 预计导航会超时吗?
  • 跟踪记录有用吗?也许它能提供线索。
  • 您能否尝试运行以DEBUG=pw:test*查看关机期间究竟发生了什么超时?
2

@dgozman — 感谢您关注此事:

  1. 不,导航不应该超时
  2. 已私下向您发送追踪信息。
  3. 日志:
    
    pw:test setup playwright +0ms
    pw:test setup _browserOptions +0ms
    pw:test setup baseURL +1ms
    pw:test setup _combinedContextOptions +0ms
    pw:test setup _artifactsDir +0ms
    pw:test setup _setupContextOptionsAndArtifacts +0ms
    pw:test setup browserName +0ms
    pw:test setup browser +0ms
    pw:test setup _contextFactory +302ms
    pw:test setup context +1ms
    pw:test setup page +12ms
    pw:test teardown page +12s
    pw:test teardown context +0ms
    pw:test teardown _contextFactory +0ms

关闭环境时超出 30000 毫秒的超时时间

关闭环境时超出 30000 毫秒的超时时间

3

现在,我再次看到了 GPU 停顿问题,如https://github.com/microsoft/playwright/issues/12756中所述。

我很困惑 :( 而且不幸的是,这只发生在一个特定的 URL 上。并且发生在多个同事身上。

注释掉screenshot: on可以让测试通过,而打开则会导致测试失败。

  pw:browser <launching> /Users/navsingh/Library/Caches/ms-playwright/chromium-978106/chrome-mac/Chromium.app/Contents/MacOS/Chromium --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-p
  ✘  [Desktop Chrome] › Reports/second-file.spec.js:5:6 › example test (30s)4j1n2rz/T/playwright_chromiumdev_profile-7wjLHL --remote-debugging-pipe --no-startup-window +0ms
  pw:browser <launched> pid=96339 +6ms
  pw:browser [pid=96339][err] [0321/152555.171230:ERROR:ssl_client_socket_impl.cc(996)] handshake failed; returned -1, SSL error code 1, net_error -201 +5s
  pw:browser [pid=96339][err] [0321/152603.895002:ERROR:gl_utils.cc(319)] [.WebGL-0x4804f2f800]GL Driver Message (OpenGL, Performance, GL_CLOSE_PATH_NV, High): GPU stall due to ReadPixels +9s

Timeout of 30000ms exceeded while shutting down environment
  pw:browser [pid=96339] <kill> +1m
  pw:browser [pid=96339] <will force kill> +0ms
  pw:browser [pid=96339] starting temporary directories cleanup +1ms
  pw:browser [pid=96339] finished temporary directories cleanup +144ms
9

语境:

Playwright Version: 1.20.0 and 1.19.0
Operating System: Mac
Node.js version: 14.15.3
Browser: Chrome
Extra: [any specific details about your environment]

我可以使用以下方法在 Playwright 1.20.0、1.19.0 中复制此错误:

{
      name: 'Google Chrome',
      use: {
        channel: 'chrome',

      },
    },

我有一个测试,使用其他浏览器大约需要 7-8 秒才能运行。当我使用 Chrome 时,需要 39-40 秒才能完成,然后出现错误

Timeout of 30000ms exceeded while shutting down environment

但我的测试仍然显示已通过。

以下是我遇到超时关闭错误时的项目配置(认为这可能会有所帮助,因为它每次都可以重现):

projects: [
    // {
    //   name: 'chromium',
    //   use: {
    //     ...devices['Desktop Chrome'],
    //   },
    // },

        {
          name: 'Smoke',
          grep: /@smoke/,
          retries: 0,
        },

    // {
    //   name: 'firefox',
    //   use: {
    //     ...devices['Desktop Firefox'],
    //   },
    // },

    // {
    //   name: 'webkit',
    //   use: {
    //     ...devices['Desktop Safari'],
    //   },
    // },

    /* Test against mobile viewports. */
    // {
    //   name: 'Mobile Chrome',
    //   use: {
    //     ...devices['Pixel 5'],
    //   },
    // },
    // {
    //   name: 'Mobile Safari',
    //   use: {
    //     ...devices['iPhone 12'],
    //   },
    // },

    /* Test against branded browsers. */
    // {
    //   name: 'Microsoft Edge',
    //   use: {
    //     channel: 'msedge',
    //   },
    // },
     {
      name: 'Google Chrome',
      use: {
        channel: 'chrome',

      },
    },
  ],

如果我使用它,它不会超时并会在 8 秒内完成(这是从“chromium”项目中删除评论而不是使用品牌浏览器部分):

projects: [
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
      },
    },

        {
          name: 'Smoke',
          grep: /@smoke/,
          retries: 0,
        },

    // {
    //   name: 'firefox',
    //   use: {
    //     ...devices['Desktop Firefox'],
    //   },
    // },

    // {
    //   name: 'webkit',
    //   use: {
    //     ...devices['Desktop Safari'],
    //   },
    // },

    /* Test against mobile viewports. */
    // {
    //   name: 'Mobile Chrome',
    //   use: {
    //     ...devices['Pixel 5'],
    //   },
    // },
    // {
    //   name: 'Mobile Safari',
    //   use: {
    //     ...devices['iPhone 12'],
    //   },
    // },

    /* Test against branded browsers. */
    // {
    //   name: 'Microsoft Edge',
    //   use: {
    //     channel: 'msedge',
    //   },
    // },
    //  {
    //   name: 'Google Chrome',
    //   use: {
    //     channel: 'chrome',

    //   },
    // },
  ],

我正在进行的测试:

import { test, expect } from '@playwright/test';
import { DotComPage } from '../pages/dotcom.page';

test.describe("Dotcom UI tests", function () {

    test.beforeEach(async function({page}) {
    const dotComPage = new DotComPage(page);
    await dotComPage.get();
    await dotComPage.firstTimeButton.click();
    expect(dotComPage.firstTimeButton.isHidden());
   })

    test("Click Shop Button", async ({page}) => {
        const dotComPage = new DotComPage(page);
        let pagePromise = page.context().waitForEvent('page');
        await dotComPage.shopNavButton.click(); //opens new tab
        const newPage = await pagePromise;
        await newPage.bringToFront();
        await newPage.waitForLoadState('networkidle');
        expect(newPage.url()).toContain("landing?shopperSource=PHX-newDotCom");
    })
})

如果需要,我可以提供完整的配置。

0

@bshostak - 您也可以发布日志吗?

DEBUG=pw:test* DEBUG=pw:browser

7

我从 1.18 升级到 1.20 后也遇到了这个问题

上下文:Playwright 版本:1.20.0 操作系统:Windows 10 Node.js 版本:v16.13.1 浏览器:Chromium

正如@Nav-2d 所暗示的,当屏幕截图设置为“开”或“仅在失败时”时,似乎会发生这种情况。将其设置为“关”即可使其正常工作。

1

@Nav-2d 希望我做对了。我没有看到任何执行 pw:test 命令的日志。

pw:browser <launching> /Users/bshostak/Library/Caches/ms-playwright/chromium-978106/chrome-mac/Chromium.app/Contents/MacOS/Chromium --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-
  ✓  [chromium] › dotcom2.spec.ts:16:5 › Dotcom UI tests › Click Shop Button (9s)2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=/var/folders/4z/p2dnz0g14r3dhfmwsdmz3vrr0000gq/T/playwright_chromiumdev_profile-98eBl1 --remote-debugging-pipe --no-startup-window +0ms
  pw:browser <launched> pid=43862 +6ms
  pw:browser [pid=43862][err] [0323/092549.121031:ERROR:command_buffer_proxy_impl.cc(125)] ContextResult::kTransientFailure: Failed to send GpuControl.CreateCommandBuffer. +520ms
 pw:browser [pid=43862] <gracefully close start> +10s
  pw:browser [pid=43862] <process did exit: exitCode=0, signal=null> +28ms
  pw:browser [pid=43862] starting temporary directories cleanup +0ms
  pw:browser [pid=43862] finished temporary directories cleanup +4ms
  pw:browser [pid=43862] <gracefully close end> +0ms
4

这可能是同一个问题 #12711,将在下一个 v1.20.1 版本中修复。

0

@dgozman——我们可以尝试@next验证一下吗?

0

我可以确认我的测试通过了npm i playwright@1.20.1-beta-1648061377000。谢谢!!

8

看起来 v1.20.1 修复了这个问题。