How do I configure retries for specific test cases in Playwright Test?


Configuring Retries for Specific Test Cases

To configure retries for specific test cases in @playwright/test, you can use the test.describe.configure() method. This allows you to set different retry settings for different groups of tests.

Here's an example of how to configure retries for a group of tests:

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

test.describe.configure({ retries: 2 })('Flaky tests', () => {
  test('Test case 1', async ({ page }) => {
    await page.goto('https://ray.run/');
    // Your test code here

  test('Test case 2', async ({ page }) => {
    await page.goto('https://ray.run/');
    // Your test code here

In this example, the two test cases within the "Flaky tests" group will be retried up to 2 times if they fail.

If you want to retry all failed test cases after all other test cases have been run, set the global retries option in your configuration file or use the command line argument --retries=3. Playwright Test will automatically retry failing test cases until they pass or reach the maximum number of retries specified.

Keep in mind that when running with retries enabled, failed and flaky test cases are retried together as part of one worker process. Delaying retries for specific test cases may affect the overall testing time since those delayed retry attempts will be executed along with any subsequent failed/flaky attempts.

By using these options, you can optimize testing time while ensuring reliable results from your automated testing suite.

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.