Test Retries | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Advanced Tricks and Techniques
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore the retry feature of Playwright , which automatically retries failed tests to enhance the stability of test suites. This feature is particularly useful for failures caused by temporary issues, such as elements not being found. High-Level Behavior of Playwright When the retry feature is: Off: Playwright runs tests in a new worker (a clean browser session). If a test fails, a new worker is created for subsequent tests. On: If a test fails, Playwright retries the failed test in a new worker, ensuring a clean environment for the retry. Configuring the Retry Feature To configure retries in your Playwright framework: Open the playwright.config.ts file. Set the retries option. For example, to enable one retry locally, set: retries: 1 To run tests sequentially, set parallel to false . Overriding Retry Settings You can override global retry settings for specific tests using: test.describe.configure({ retries: 2 }) This allows you to specify different retry counts for flaky tests. Additional Control During Retries To perform actions before a retry (e.g., cleaning the database), use: if (testInfo.retry) { /* cleanup code */ } Summary The retry mechanism in Playwright enhances test reliability by isolating retries in new workers. Configuration is done in playwright.config.ts , and overrides can be applied at the test level. Additionally, you can manage preconditions for retries using the testInfo object.