Test Retries | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Advanced Tricks and Techniques
Instructor: Artem Bondar
Lesson Summary
Automatic Test Retry is a feature in Playwright that allows tests to be retried automatically if they fail. This summary outlines how the retry mechanism works and how to configure it. How the Retry Mechanism Works When a test is executed, Playwright launches a worker , which is essentially a browser session for running the test. If a test fails: The current worker is shut down. A new worker is launched for the next test to ensure a clean browser state. If retries are enabled: Upon a test failure, a new worker is created to retry the failed test in a fresh session. If the retry passes, the execution continues with subsequent tests. Configuring Retries Retries can be configured in the playwright.config.ts file: The default setting allows for two retries in CI/CD environments. For local runs, the default is zero retries . To change the number of retries, modify the retries line in the configuration file. For example: retries: 1 Running Tests When running tests, ensure you use the command line for the retry feature to work. Retries will not function if tests are run through the Playwright extension. Configuring Specific Tests You can also set retries for specific test suites or files using test.describe.configure . This allows for more flexibility, especially for flaky tests. Cleaning Up Before Retries To ensure a clean environment before a retry, use the testInfo object within your tests. Check testInfo.retries to determine if a retry is occurring and perform necessary cleanup: if (testInfo.retries) { /* cleanup code */ } This concludes the overview of the automatic test retry feature in Playwright. Happy testing!