question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

8reactions
super-briancommented, May 19, 2022

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);
    });
6reactions
amrsa1commented, May 20, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Playwright error (Target closed) after navigation
You can need to wait for the navigation, not the press action. const context = await browser.newContext(); const page = await context.
Read more >
playwright._impl._api_types.error: execution context was ...
I came into this issue today, and found that this problem occurs in this case: I was use page object loading a url...
Read more >
Multi-page scenarios | Playwright 中文文档
The page event on browser contexts can be used to get new pages that are created in the context. This can be used...
Read more >
Browser - MarketSquare
The Open Browser keyword opens a new browser, a new context and a new page. This keyword is useful for quick experiments or...
Read more >
BrowserContext (Playwright - Main Library 1.12.1 API)
open call, the popup will belong to the parent page's browser context. Playwright allows creation of "incognito" browser contexts with browser.newContext() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found