To manage failing or flaky tests, you can use the test retries feature in Playwright Test. By default, failing tests are not retried. But you can change this by specifying the number of retry attempts.
Use the --retries
flag followed by the number of retry attempts. Here's how:
npx playwright test --retries=3
You can also set the number of retry attempts in the playwright.config.ts
file.
import { defineConfig } from '@playwright/test';
export default defineConfig({
retries: 3,
});
Playwright Test categorizes tests into "passed", "flaky", and "failed". You can detect whether a test is being retried at runtime using testInfo.retry
.
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 });
test('test 1', async ({ page }) => {
// ...
});
test('test 2', async ({ page }) => {
// ...
});
});
Use test.describe.serial()
to ensure that dependent tests always run together and in order.
import { test } from '@playwright/test';
test.describe.configure({ mode: 'serial' });
test.beforeAll(async () => {
/* ... */
});
test('first good', async ({ page }) => {
/* ... */
});
test('second flaky', async ({ page }) => {
/* ... */
});
test('third good', async ({ page }) => {
/* ... */
});
By enabling test retries and configuring them appropriately, you can control how many times failing or flaky tests should be retried. For more on handling flaky tests, check out this post.
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].