Skip to content

[Question] browser.newContext failed why? #9784

@mtt87

Description

@mtt87

This is randomly happening for me only on GitLab CI, when I run tests locally everything is fine 100% of the times.

I'm using this config

e2e:
  stage: e2e
  image: mcr.microsoft.com/playwright:focal
  script:
    - npm run test:e2e
"test:e2e": "DEBUG=pw:api playwright test e2e",
const config: PlaywrightTestConfig = {
  workers: 1,
  retries: 0,
  timeout: 150000,
  globalSetup: './globalSetup',
}

In my global setup I signup 3 different type of users and save their 3 browser context into json storage.
Something like this

async function globalSetup() {
  const browser = await chromium.launch({
    slowMo: 2000,
  })
  const baseContext = await browser.newContext({
    baseURL: frontendBaseUrl,
  })
  // do stuff
  await baseContext.context().storageState({ path: 'baseStorageState.json' })
    const ownerContext = await browser.newContext({
    baseURL: frontendBaseUrl,
  })
  // do stuff
  await ownerPage.context().storageState({ path: 'ownerStorageState.json' })
  // repeat

  await browser.close()
}

Then I have a test.describe.serial("3 roles", ...) that is testing operations on the 3 roles. I know serial is not advised but I need to because I have a use case where the first user has to invite others in their "workspace" and the other tests can only start when the invite has been created and then consumed.

test.describe.serial('Console', () => {
  let inviteLinkAdmin: string
  let inviteLinkViewer: string
  let browser: ChromiumBrowser

  test.beforeAll(async () => {
    browser = await chromium.launch({
      slowMo: 500,
    })
  })

  test.afterAll(async () => {
    await browser.close()
  })

  test('OWNER ROLE', async () => {
    const context = await browser.newContext({
      storageState: 'ownerStorageState.json',
      baseURL: frontendBaseUrl,
    })
    // do stuff
  })

  test('VIEWER ROLE', async () => {
    const context = await browser.newContext({
      storageState: 'viewerStorageState.json',
      baseURL: frontendBaseUrl,
    })
    // do stuff
  })

Screenshot 2021-10-26 at 12 34 16

As you can see I have DEBUG=pw:api enabled but it still doesn't tell me exactly why browser.newContext failed, is there a way to know?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions