This thread is trying to answer question "How can I configure the pipeline to only fail when a certain number of tests have failed or are flaky?"
Related Ask AI answer for "How do I use the test retries feature in Playwright Test to manage failing or flaky tests?".
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.
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].