How do I configure the number of retry attempts for failing tests in Playwright Test?


Configuring Retry Attempts in Playwright Test

Yes, you can influence the timing of retries in Playwright Test. By default, failing tests aren't retried. But you can specify the number of retry attempts either through the command line or in the configuration file.

Command Line Configuration

Use the --retries flag followed by the desired number of retries. For example, npx playwright test --retries=3 gives failing tests 3 retry attempts.

Configuration File

You can also configure retries in the playwright.config.ts file. Use defineConfig to set the retries property. Here's an example:

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

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

Test Status

Playwright Test categorizes tests into "passed", "flaky", and "failed". "Passed" are tests that passed on the first run. "Flaky" are tests that failed initially but passed when retried. "Failed" are tests that failed on all runs including retries.

Retries at Runtime

You can detect whether a test is being retried or not by checking testInfo.retry. This property is accessible within any test, hook, or fixture.

Serial Mode

Playwright Test provides a serial mode (test.describe.serial()) for grouping dependent tests together. If one test fails in serial mode, all subsequent tests in the group are skipped. All tests within a serial group are retried together.

Isolation of Tests

Playwright Test creates an isolated Page object for each test. If you want to reuse a single Page object between multiple tests, you can create your own Page object in test.beforeAll() and close it in test.afterAll().

For more information, check out this blog post: Exploring the Various Retry APIs of Playwright for Robust Testing.


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 Discord Threads

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.