Rayrun

How do I enable test retries in Playwright?

Answer

To enable test retries in @playwright/test, you can use the --retries command-line option or configure it in the playwright.config.ts file.

For example, to give failing tests three retry attempts, run:

npx playwright test --retries=3

Alternatively, you can set the retries in the playwright.config.ts file:

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

export default defineConfig({
  retries: 3,
});

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

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

test.describe(() => {
  test.describe.configure({ retries: 2 });

  // Tests go here...
});

To access the retry count 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' });

// Tests go here...

Remember, it's better to make your Playwright Test cases isolated so they can be efficiently run and retried 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.

TwitterGitHubLinkedIn
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 [email protected].