What is the process to enable test retries in Playwright?


Enabling Test Retries in Playwright

To enable test retries in Playwright, you can use the command npx playwright test --retries=3. This will give failing tests three retry attempts.

You can also set this up in the playwright.config.ts configuration file with defineConfig({retries: 3}).

Playwright Test classifies tests as "passed", "flaky", or "failed". Passed tests are those that passed on the first run; flaky tests are those that failed on the first run but passed when retried; and failed tests are those that failed on both their initial run and all subsequent retries.

You can detect retries at runtime with testInfo.retry. This is accessible to any test, hook or fixture. For example, you could clear some server-side state before a retry like this:

import { test } 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(). Here's how:

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

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

  test('test 1', async ({ page }) => {
    // ...

  test('test 2', async ({ page }) => {
    // ...

If you have dependent tests that need to run together and in order, use test.describe.serial(). If one of these tests fails, all subsequent ones will be skipped unless you have enabled retries.

For more insights on handling flaky tests, check out this blog post.


Thank you!
Was this helpful?
Still have questions?

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

Related Questions

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.