playwright: [BUG] browser.newContext: Target page, context or browser

Context:

  • Playwright Version: 1.20.1
  • Operating System: any
  • Node.js version: 14.6
  • Browser: firefox

Error in debug mode

  ✘  [Desktop Firefox] › PublicSearch/LandingPage.test.ts:56:5 › Landing page Test Suite › User can search for  (1ms)
  pw:browser [pid=30113] <process did exit: exitCode=0, signal=null> +8ms
  pw:browser ffmpeg onkill exitCode=0 signal=null +0ms
  pw:browser [pid=30113] starting temporary directories cleanup +0ms
  pw:browser [pid=30113] finished temporary directories cleanup +0ms
  pw:browser [pid=30113] <gracefully close end> +0ms
  
  
  1) [Desktop Firefox] › PublicSearch/LandingPage.test.ts:56:5 › Landing page Test Suite › User can search for a city using EN/DE/IT lang while selected lang is FR 

    browser.newContext: Target page, context or browser has been closed

Code Snippet

    test.beforeEach(async ({ page, landingPage }) => {
        await page.goto(path.en.landingPage, { waitUntil: "load", timeout: 30000 })
        await landingPage.waitForText('Log in')
    });
    
        test('User can search for a city using EN/DE/IT lang while selected lang is FR', async ({ page, landingPage }) => {
        await page.goto(path.fr.landingPage, { waitUntil: "load" })
        await landingPage.searchForCity('c')
        await expect.soft(page.locator('text=c >> nth=0')).toBeVisible();
        await landingPage.searchForCity('c')
        await expect.soft(page.locator('text=zurich >> nth=0')).toBeVisible();
        await landingPage.searchForCity('c')
        await expect.soft(page.locator('text=zurich >> nth=0')).toBeVisible();
    });

Describe the bug

I have noticed that I’m getting the following error so often browser.newContext: Target page, context, or browser when a test is running against firefox, it happens randomly with different tests, I failed to find certain steps to reproduce.

but it’s obviously happening when you run multiple tests with firefox. especially if the tests are executed in a very short time, this is my guess, all failure was happening on the hook

Screenshot 2022-04-05 at 16 07 19

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 21 (5 by maintainers)

Most upvoted comments

I have exactly the same issue. this error line shows randomly only for firefox when I ran tests with --headed option.

browser.newContext: Target page, context or browser has been closed

And when I see the test report, there is read ‘x’ next to the ‘Before Hooks’ while ‘After Hooks’ has green checkmark.

it happened to this simple test (and another simple test, which are all after other simple tests), which uses a few page objects, and I don’t handle browser or context at all. I guess, this is truly a bug

    test(`2 Homepage - ${user.level}`, async ({ page }) => {
      const empty = new Empty(page);
      await empty.gotoTestPage();

      const loginAspx = new LoginAspx(page);
      await loginAspx.clickLogin();

      const login = new Login(page);
      await login.loginWith(user.id, user.pw);

      const home = new Home(page);
      await home.verifyElements(user.level);
    });

This issue is really serious and causing alot of falkiness.

I have decided to disable all test against firefox to avoid such cases.

@mxschmitt could we reopen this ticket again, i might be able to provide a reproducible code.

mxschmitt could we reopen this issue? seems more people is encountering the bug recently

I’m also getting this randomly with firefox (not with other browsers). Maybe once every dozen or so test runs.

I have the same issue

I have this problem Error: browser.newContext: Target page, context or browser has been closed.
I checked my code, open and close all contexts, according to the documentation. It happens randomly. Оn the same test. If I remove the test or skip, the error will start to occur in another test. There is only one drop during the entire run, and if you run many tests at once. There is no local problem in the test. image Please open the issue and try to fix it. This makes my tests flaky. PW version 1.35.0 Run tests in 4 workers, fullyParallel: true, in one browser (don’t use projects). Browser as a default - chrome. Node.js version: 16.15.0

@amrsa1 lots of fixes have landed to Firefox recently. Could you please try @playwright/test@next and check if things are improved?

npm i @playwright/test@next 
npx playwright install firefox

yeah I am also facing this issue with Firefox every now and then, @mxschmitt please reopen it.

Getting the same issue frequently: browser.newContext: Target page, context or browser has been closed it fails for random test cases but always in beforeEach hook, when many tests are ran in headed mode