How do I enable retries for failing tests in Playwright?


To enable retries for failing tests in @playwright/test, you can specify the number of retry attempts either through the command line or in the configuration file.

Run the following command to give failing tests 3 retry attempts:

npx playwright test --retries=3

Or, update the playwright.config.ts file:

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

export default defineConfig({
  // Give failing tests 3 retry attempts
  retries: 3,

When retries are enabled, tests are categorized as "passed", "flaky", or "failed" based on their initial run and retry results.

You can also detect retries at runtime using testInfo.retry:

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

test('my test', async ({ page }, testInfo) => {
  if (testInfo.retry) await cleanSomeCachesOnTheServer();
  // ...

To specify retries for a specific group of tests or a single file, use test.describe.configure():

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

test.describe(() => {
  // All tests in this describe group will get 2 retry attempts.
  test.describe.configure({ retries: 2 });

  test('test1', async ({ page }) => {
    // ...
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.