Designing a resilient test harness for concurrent, stateful E2E scenarios in Playwright
Description and use
A resilient Playwright test harness was built using per-worker isolated Docker containers and API-driven fixtures, eliminating flaky tests caused by shared backend state.
Problem
Running concurrent, stateful E2E tests causes flaky failures due to shared backend resources; browser context isolation alone is insufficient.
Outcome
Implemented per-worker isolated backend environments with API-driven state provisioning and robust cleanup, eliminating flaky tests and improving CI/CD reliability.
Workflow
- Spin up a fresh Docker Compose/Testcontainers stack per Playwright worker using globalSetup.
- Map unique ports and database instances for each environment.
- Use custom Playwright fixtures to create a unique user and provision complex state via direct API calls before UI interaction.
- Ensure fixture logic is idempotent.
- Run tests against the isolated environment.
- After each test, perform test-specific cleanup with test.afterEach (e.g., logout, delete temp files).
- After all tests, invoke globalTeardown to stop and remove containers, guaranteeing cleanup even on failures.
Evidence
Leverage dynamic, containerized environments for true isolation.
Use custom Playwright fixtures to provision specific states before UI interaction via direct API or database calls.
- Record date: 2026-09-11T15:15:24.922Z