Skip to content
jshacks.dev
Testing

Use Playwright test.describe.configure for serial tests

Run a group of dependent Playwright tests in order in one worker with test.describe.configure and mode serial, and retry them together.

1 min read
Summarize in AI

Playwright runs tests in parallel and isolates them, which is right until a flow genuinely depends on the previous step, such as create, edit, delete. Mark that group as serial.

tests/article-lifecycle.spec.jsJavaScript
import { test, expect } from '@playwright/test';

test.describe.configure({ mode: 'serial' });

let page;

test.beforeAll(async ({ browser }) => {
  page = await browser.newPage();
});

test.afterAll(async () => {
  await page.close();
});

test('creates a draft', async () => {
  await page.goto('http://localhost:3000/new');
  await page.getByLabel('Title').fill('Hello');
  await page.getByRole('button', { name: 'Save draft' }).click();
  await expect(page.getByText('Draft saved')).toBeVisible();
});

test('publishes the draft', async () => {
  await page.getByRole('button', { name: 'Publish' }).click();
  await expect(page.getByText('Published')).toBeVisible();
});
Text
Running 2 tests using 1 worker
  ✓  1 article-lifecycle.spec.js:15:5 › creates a draft
  ✓  2 article-lifecycle.spec.js:22:5 › publishes the draft
  2 passed

In serial mode the tests of the group run in order in one worker. If one fails, the rest are skipped, and on a retry the whole group starts again from the first test, as the Playwright docs explain.

The Playwright team recommends independent tests instead. Prefer one test with several steps, or fixtures that create the state, and keep serial mode for flows you cannot split.

Share

More snippets

Debugging

Debug a single Vitest test in VS Code

Run one Vitest file under the VS Code debugger with a launch configuration that passes the open file, so breakpoints in tests and source work. Vitest 3.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.