← Back to Discord Forum

Getting Error: browser.newPage: Target page, context or browser has been closed

ashokchhetriposted in #help-playwright
Open in Discord

I have overall 3-4 files of tests, now when we are trying to execute with one worker we are facing this issue most of the time. But if we use 1 worker per test file this issue not happens. So not sure what's the cause here. As currently we have less number of test cases and each test is independent so we are using 1 worker.


This thread is trying to answer question "Do we need to have separate workers for each test file to prevent the 'browser.newPage: Target page, context or browser has been closed' error?"

2 replies

Things to check Concurrency Issue: Make sure that each test is running in its isolated context, and resources (like browser pages) are not shared between different tests. Cleanup: Ensure that you’re not prematurely closing the browser, context, or pages during the test execution. You may want to look into the setup and teardown process for each test to see if something is being closed before it should be. Resource Constraints: one worker for all your tests might be to resource heavy, potentially look into sharding.


So we need to have separate workers for each files ?

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.