[microsoft/playwright]问题:Playwright 组件测试在 Jenkins 中启动浏览器

2024-04-10 955 views
4

这就是我剧作家配置的样子。


import { resolve } from 'path';
import { defineConfig, devices } from '@playwright/experimental-ct-react';

export default defineConfig({
  testDir: './playwright-ct',
  /* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */
  snapshotDir: './playwright-ct/__snapshots__',
  /* Maximum time one test can run for. */
  timeout: 30 * 1000,
  /* Run tests in files in parallel */
  fullyParallel: true,
  /* Fail the build on CI if you accidentally left test.only in the source code. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 2 : 0,
  /* Opt out of parallel tests on CI. */
  workers: process.env.CI ? 1 : undefined,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  reporter: [['html', { open: 'on-failure' }]],
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'retain-on-failure',
    baseURL: 'https://localhost',
    // baseURL: process.env.STAGING === '1' ? 'http://staging.example.test/' : 'http://example.test/',
    /* Port to use for Playwright component endpoint. */
    ctPort: 3100,
  },

  /* Configure projects for major browsers */
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] }
    },
    {
      name: 'Mobile Chrome',
      use: {
        ...devices['Pixel 5']
      }
    }
  ]
});

这是一些测试示例


 test.beforeAll(async ({ mount }) => {
    await mount(<ComponentA />);
  });
  test.beforeEach(async ({ page }) => {
    let requestURL;
    await page.route('/abcd/sax/**', async (route) => {
      requestURL = route.request().url();
      route.continue();
    });
    await page.waitForLoadState('networkidle');
  });

 test('PRODUCT SHARE CLICK EVENT', async ({ page }) => {
   await page.locator('[data-auto-id="btn1"]').click();
   expect(requestURL).toContain('SHARE');
 });

 test('SIZE CHANGE EVENT', async ({ page }) => {
    await page.locator('[data-auto-id="BTN2"]').click();
    await expect(requestURL).toContain('SIZE');
 });

当我在构建管道上运行它们时,它们在本地运行良好,我收到以下错误日志。

2023-03-09 15:00:27      browserType.launch: Browser closed.
2023-03-09 15:00:27      ==================== Browser output: ====================
2023-03-09 15:00:27      <launching> /home/jenkins/.cache/ms-playwright/chromium-1048/chrome-linux/chrome --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate --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 --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-o7zE6N --remote-debugging-pipe --no-startup-window
2023-03-09 15:00:27      <launched> pid=6887
2023-03-09 15:00:27      [pid=6887][err] /home/jenkins/.cache/ms-playwright/chromium-1048/chrome-linux/chrome: symbol lookup error: /home/jenkins/.cache/ms-playwright/chromium-1048/chrome-linux/chrome: undefined symbol: gbm_bo_get_modifier

jenkins 似乎正在尝试打开浏览器来运行测试,这很奇怪,因为它应该无头运行,或者我不确定这里会发生什么。

回答

3

您的 Jenkins 运行在哪个 Linux 发行版上?确保使用 Ubuntu 20/22 或 Debian 11,请参阅此处

7

理想情况下,我们之前也在项目中进行了剧作家测试,但从未出现过此错误,它仅在剧作家组件测试中出现。 @mx施密特

0

这些错误看起来像是您在不受支持的 Linux 发行版上运行 Playwright,因此我想问一下。当涉及启动浏览器时,Playwright 组件测试与正常的 Playwright 端到端测试没有太大区别。

3

@mxschmitt是的,这很奇怪,因为我们在同一发行版中运行剧作家测试,这里似乎是通过日志浏览器启动,然后关闭或其他什么。我需要安装额外的依赖项或其他东西吗?


2023-03-09 16:28:26      <launched> pid=7060
2023-03-09 16:28:26      [pid=7060][err] /home/jenkins/.cache/ms-playwright/chromium-1048/chrome-linux/chrome: symbol lookup error: /home/jenkins/.cache/ms-playwright/chromium-1048/chrome-linux/chrome: undefined symbol: gbm_bo_get_modifier
3

有没有办法在这里调试 Jenkins 构建,以找出到底是什么导致了这个错误,我确信 Linux 发行版不会导致它,广告除了组件测试之外,其他剧作家测试工作正常。

1

理想情况下,这是主要错误。

error: /home/jenkins/.cache/ms-playwright/chromium-1048/chrome-linux/chrome: undefined symbol: gbm_bo_get_modifier

0

那么您使用的是哪个 Linux 发行版?

4

@mxschmitt 我们正在使用 Linux (amd64)

9

这不是 Linux 发行版,您使用的是 CentOS、Debian 还是 Ubuntu,哪个版本?

9

@mxschmitt 是所附图片的帮助。 D0FB4671-F79B-4DF9-9794-0183E35D5D5C

1

然后你是在 Docker 中运行测试还是在flatcar操作系统中运行测试?因为这不会被支持。

1

@mxschmitt 一切都在 docker 内运行,代理是 flatcar,尽管如此,所有其他剧作家测试都工作正常,除了组件测试,可能是一些配置问题,我不确定:)

0

也许是 Jenkinsfile 问题,并且您没有在 Docker 内运行所有测试而仅运行端到端测试?

5

@mxschmitt我们有一个关于运行剧作家测试的简单设置,yarn test:ci使用剧作家配置文件运行正常的剧作家测试,然后使用剧作家-ct配置运行剧作家-ct测试。

  withNvm {
             sh 'npx playwright install'
             sh 'yarn test:ci'
          }
4

不幸的是,我们对 Jenkins 或您的设置没有经验,因为undefined symbol: gbm_bo_get_modifier总是与缺少系统依赖项有关,我们只能建议您运行npx playwright install --with-deps.

8

@mxschmitt 不用担心,感谢您的帮助,我们的团队能够解决我们已经转移npx playwright install到考虑我们的剧作家版本来下载二进制文件的问题。