To configure retries in Playwright Test, you have several options. You can use the command line, update the configuration file, or specify retries for specific test groups.
Run your tests with the --retries
flag, like this:
npx playwright test --retries=3
This command retries failing tests 3 times before marking them as failed.
Add the retries
property to your playwright.config.ts
file:
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
retries: 3,
// ...
};
export default config;
Use test.describe.configure()
to set retries for a group of tests:
import { test } from '@playwright/test';
test.describe(() => {
test.describe.configure({ retries: 2 });
test('test 1', async ({ page }) => {
// ...
});
test('test 2', async ({ page }) => {
// ...
});
});
Access testInfo.retry
to detect retries and perform actions like clearing server-side caches:
import { test } from '@playwright/test';
test('my test', async ({ page }, testInfo) => {
if (testInfo.retry) await cleanSomeCachesOnTheServer();
// ...
});
These methods allow you to configure and handle retries in Playwright Test according to your needs.
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].