Day 12: Parallel Execution and Sharding for Speed
This is Day 12 of the 21-Day Playwright with TypeScript Challenge. One lesson per day. Zero to production-ready in 3 weeks.
๐ญ Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.
Playwright runs tests in parallel by default. Each test gets its own BrowserContext โ isolated cookies, storage, cache. No shared state means safe parallelism with zero configuration.
Contents
Config for Parallel
export default defineConfig({
fullyParallel: true, // All tests run in parallel
workers: process.env.CI ? 2 : undefined, // Auto-detect locally
});
Sharding Across CI Runners
# GitHub Actions โ 4 parallel shards
jobs:
test:
strategy:
matrix:
shard: [1/4, 2/4, 3/4, 4/4]
steps:
- run: npx playwright test --shard=${{ matrix.shard }}
๐ Level Up Your Playwright
From locators to CI pipelines โ build a production-grade Playwright + TypeScript framework step by step.
Test Isolation Requirements
- Each test creates own data (no shared accounts)
- No test depends on another test running first
- Use unique identifiers (timestamp + random suffix)
- Clean up in afterEach, not beforeEach
Speed Comparison
| Setup | 100 Tests | Speedup |
|---|---|---|
| Sequential (1 worker) | 25 min | 1x |
| Parallel (4 workers) | 7 min | 3.5x |
| Sharded (4 CI runners) | 2 min | 12.5x |
Tomorrow (Day 13): Debugging with Trace Viewer, UI Mode, and Inspector.
๐ Master Playwright End to End
Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.
