Login and saved auth state
Sign in once, dump the storage state, and reuse it across every test that needs an authenticated session. No repeated login flows, no flaky form-fill races.
Capture the state once
Run this once before the main suite — wire it as a global setup project so CI does not skip it.
Reuse it everywhere
Every BrowserContext created from then on starts with the saved
cookies and localStorage. The first navigation in every test arrives
already-authenticated.
Per-project override (matrix runs):
TypeScript
Then load it on subsequent runs:
Multiple roles
One state file per role:
Invalidation
When the auth state goes stale (cookie expiry, password rotation), the
first authenticated test will redirect to /login. Detect with a guard
in before_each:
Why not just log in per test
A login flow costs ~1.5 s on a fast site, ~5 s on a slow one. Saved state costs zero. On a 200-test suite at 4 workers the savings are 5–25 minutes per run. The state file is also more deterministic — no race against an async login form.