Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

resetContext() fails to close a page. #612

@ychaudhari

Description

@ychaudhari

Describe the bug
jestPlaywright.resetContext(); fails to close a page.

To Reproduce
Run following test with DEBUG=pw:api

describe('Testing', () => {
  beforeEach(async () => {
    await jestPlaywright.resetContext();
  });
  it('test1', async () => {
    await page.goto('http://www.google.com');
  });
});

Expected behavior
No fails in the logs

Actual behavior
Shows following error in logs

  pw:api => page.close started +4ms
  pw:api <= page.close failed +7ms

Full log

  pw:api => browserType.connect started +0ms
  pw:api <= browserType.connect succeeded +25ms
  pw:api => browser.newContext started +5ms
  pw:api <= browser.newContext succeeded +20ms
  pw:api => browserContext.newPage started +6ms
  pw:api <= browserContext.newPage succeeded +143ms
  pw:api => browserContext.close started +4s
  pw:api <= browserContext.close succeeded +14ms
  pw:api => browser.newContext started +4ms
  pw:api <= browser.newContext succeeded +8ms
  pw:api => page.close started +4ms
  pw:api <= page.close failed +7ms
  pw:api => browserContext.newPage started +5ms
  pw:api <= browserContext.newPage succeeded +95ms
  pw:api => page.goto started +5ms
  pw:api navigating to "http://www.google.com", waiting until "load" +7ms
  pw:api   navigated to "https://www.google.com/?gws_rd=ssl" +631ms
  pw:api   navigated to "https://www.google.com/?gws_rd=ssl" +226ms
  pw:api   "domcontentloaded" event fired +4ms
  pw:api   "load" event fired +540ms
  pw:api <= page.goto succeeded +5ms
  pw:api => browser.close started +8ms
  pw:api <= browser.close succeeded +8ms
 PASS   browser: chromium  tests/one.test.ts (5.595 s)

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Windows
  • Playwright version 1.9.1
  • jest-playwright version 1.4.7

Jest configuration (Either in the package.json > jest or in the jest.config.js):

import type { Config } from '@jest/types';

export default async (): Promise<Config.InitialOptions> => {
 return {
   verbose: true,
   setupFilesAfterEnv: ['./jest.setup.ts', 'expect-playwright'],
   preset: 'jest-playwright-preset',
   testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'],
   testPathIgnorePatterns: ['/node_modules/'],
   transform: {
     '^.+\\.ts?$': 'ts-jest',
   },
   testEnvironment: './CustomEnvironment.js',
 };
};

jest-playwright.config.js

module.exports = {
  browsers: ['chromium'],
  connectOptions: {},
  contextOptions: {},
  launchOptions: {
    headless: true,
  },
};

Additional context
N/A

Question
What is the right way to reset browser/context/pages after/before use so that we do not get any fails in the logs and we do not leave un-used objects in the memory after the test?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions