What is the process for enabling test retries in Playwright?


To enable test retries in Playwright, you can configure the number of retry attempts for failing tests. By default, there are no retries for failing tests.

To set up retries, update your playwright.config.ts file with the following code:

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

export default defineConfig({
  // Set the number of retry attempts for failing tests
  retries: 3,

This configuration gives failing tests 3 retry attempts. You can also use the command npx playwright test --retries=3 to achieve the same result.

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

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

test.describe(() => {
  // Configure 2 retry attempts for this describe group
  test.describe.configure({ retries: 2 });
  // Add your tests here...

If you need to detect retries at runtime, use testInfo.retry:

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

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

For dependent tests that should always run together and in order, use test.describe.serial():

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

test.describe.configure({ mode: 'serial' });
// Add your dependent tests here...

Remember, it's better to make your Playwright Test cases isolated so they can run and retry independently.

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.