What this thread does
Do first: Create tests/auth.setup.ts to authenticate and save state, then configure dependent browser projects to load it.
Short answer
A setup project can authenticate once for tests that safely share an account. Parallel tests that mutate server state need an account per worker instead.
What to do
| Part | Configuration |
|---|---|
| Saved state | Add playwright/.auth to .gitignore; save to playwright/.auth/user.json. |
| Setup file | In tests/auth.setup.ts, finish login and wait for the final URL or an authenticated UI signal before await page.context().storageState({ path: authFile }). |
| Setup project | In playwright.config.ts: { name: 'setup', testMatch: /.*\.setup\.ts/ }. |
| Browser projects | Set dependencies: ['setup'] and use.storageState: 'playwright/.auth/user.json'. |
| IndexedDB-backed login | Save with await page.context().storageState({ path: authFile, indexedDB: true }); IndexedDB is omitted by default. |
| Parallel mutations | Use a worker-scoped fixture (scope: 'worker') and test.info().parallelIndex to allocate distinct accounts. |
Delete expired state. To discard it between runs, place it under testProject.outputDir, which is cleared before each run. UI mode skips the setup project by default: enable setup in the filters, run auth.setup.ts with its triangle button, then disable setup again.
Limits and open questions
Browser-specific login is another reason to avoid a single shared state. Playwright does not persist sessionStorage through this API. Keep saved account state out of repositories.
Not for: Cypress session caching.
Sources
Checked
2026-11-17: Read Playwright Authentication; no command was run.
Started from a post by @Playwright (Microsoft), packaged by the editor. Original post