How do I configure test retries in Playwright?


To enable test retries in @playwright/test, you can use the --retries flag or configure it in the playwright.config.ts file. For example, to give failing tests 3 retry attempts, run:

npx playwright test --retries=3

Or, in your playwright.config.ts file, use:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  retries: 3

You can also set retries for specific groups of tests or a single file using test.describe.configure(). For instance, to give all tests in a describe group 2 retry attempts:

import { test } from '@playwright/test';

test.describe.configure({ retries: 2 })('My Test Group', () => {
  // Your tests here

To check for retries at runtime, use testInfo.retry in your test, hook, or fixture. For example, to clear server-side state before a retry:

import { test } from '@playwright/test';

test('My Test', async ({ page, testInfo }) => {
  if (testInfo.retry) {
    await page.goto('https://ray.run/clear-cache');
  // Your test code here

Remember to make your tests isolated for efficient and independent retries. Reuse a single page between tests for better performance and reliability.

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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 luc@ray.run.