microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.8k stars 3.66k forks source link

No backroundPage in the Linux CI machine when trying to build chrome extension #29545

Closed LibiZiser closed 8 months ago

LibiZiser commented 8 months ago

This the code for build extension in the fixture:

import { chromium, BrowserContext } from '@playwright/test';
import path from 'path';
import { automationPath } from 'automation/applications/common/path';
import { execSync } from 'child_process';
interface TestInfo {
  context: BrowserContext;
  extensionId: string;
}
export default async ({}, testInfo: TestInfo) => {
  testInfo = testInfo || {};
  const command = 'yarn workspace @akeyless/ztwa-extension build:prod';
  execSync(command, { encoding: 'utf-8', maxBuffer: 1000 * 10000 * 100 });
  const pathToExtension = path.join(__dirname, automationPath.extension);
  // Launch the Chromium browser context
  const context = await chromium.launchPersistentContext('', {
    headless: false,
    args: [
      --headless=new,
      --disable-extensions-except=${pathToExtension},
      --load-extension=${pathToExtension}
    ]
  });
  await new Promise(resolve => setTimeout(resolve, 3000));
  try {
    const [background] = context.backgroundPages();
    if (!background) {
      console.log('no background');
      await context.waitForEvent('backgroundpage', { timeout: 300000 });
    }
    const extensionId = background.url().split('/')[2];
    console.log('Extension ID:', extensionId);
    testInfo.context = context;
    testInfo.extensionId = extensionId;
    await context.close();
  } catch (error) {
    console.error('Error occurred while getting the extension ID:', error);
  }
};

When I run locally on Mac the run is not enter to the if (!background). When I run on ci linux I received :

Error occurred while getting the extension ID: browserContext.waitForEvent: Timeout 300000ms exceeded while waiting for event "backgroundpage"
    at _default (/home/runner/work/frontend-react/frontend-react/packages/automation/tests/SRA/sraFixture.ts:35:21)

Working with Playwright + TS

mxschmitt commented 8 months ago

This issue is not following the bug template, closing by that.