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.
Use the --retries
flag followed by the desired number of retries. For example, npx playwright test --retries=3
gives failing tests 3 retry attempts.
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,
});
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.
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.
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.
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.
If you still have questions, please ask a question and I will try to answer it.
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].