To enable test retries in @playwright/test, you can use the command line or configure it in the playwright.config.ts
file. For example, to give failing tests three retry attempts, run:
npx playwright test --retries=3
Or, configure retries in playwright.config.ts
:
import { defineConfig } from '@playwright/test';
export default defineConfig({
retries: 3,
});
To clear server-side state before a retry, use testInfo.retry
:
import { test } from '@playwright/test';
test('my test', async ({ page }, testInfo) => {
if (testInfo.retry) await cleanSomeCachesOnTheServer();
// ...
});
For specific groups or files, use test.describe.configure()
:
import { test } from '@playwright/test';
test.describe(() => {
test.describe.configure({ retries: 2 });
test('test 1', async ({ page }) => {
// ...
});
test('test 2', async ({ page }) => {
// ...
});
});
For dependent tests that should run together and in order, use test.describe.serial()
. If one test fails, subsequent ones will be skipped unless retries are enabled.
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].