beforeAll() re-runs after a test case failure when workers are set to 1. @playwright/test runs tests in worker processes, which are independent OS processes orchestrated by the test runner. When tests pass, they run in order within the same worker process. However, if a test fails, Playwright Test discards the entire worker process along with the browser and starts a new one. Testing continues in the new worker process starting with the next test.
If you enable retries and a test fails, a second worker process starts by retrying the failed test and continues from there. This means that the
beforeAll() hook runs again in the new worker process after a failed test case.
This scheme works well for independent tests and ensures that failing tests can't affect healthy ones. You can use
test.afterAll() to teardown any resources set up in
In summary, when a test case fails with workers set to 1 and retries enabled,
beforeAll() re-runs in the new worker process after discarding the previous one along with its browser instance.
If you still have questions, please ask a question and I will try to answer it.
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 email@example.com.