To enable test retries in @playwright/test after a failure, you can use the --retries
flag when running tests or configure retries in the playwright.config.ts
file.
--retries
flagRun your tests with the --retries
flag followed by the number of retry attempts you want to allow. For example, to give failing tests three retry attempts, run:
npx playwright test --retries=3
playwright.config.ts
Set the number of retries in your playwright.config.ts
file:
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
retries: 3,
};
export default config;
This will give failing tests three retry attempts.
@playwright/test categorizes tests as "passed", "flaky", or "failed". Tests that pass on the first run are "passed". Tests that fail initially but pass when retried are "flaky". Tests that fail on all retries are "failed".
When a test fails and retries are enabled, @playwright/test discards the worker process along with the browser and starts a new one. Testing continues in the new worker process, starting with the next test. The second worker process begins by retrying the failed test and continues from there.
You can detect retries at runtime with testInfo.retry
, which is accessible to any test, hook, or fixture. You can also specify retries for a specific group of tests or a single file using test.describe.configure()
.
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 protected].