published fresh until

How do I stop my Playwright tests logging in again in every test?

Summary As of November 2026, save login state in playwright/.auth/user.json from a setup project, make browser projects depend on setup and load that file. Use separate accounts per parallel worker when tests change shared data. Configure storageState: 'playwright/.auth/user.json'.

Not for Cypress session caching.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

PartConfiguration
Saved stateAdd playwright/.auth to .gitignore; save to playwright/.auth/user.json.
Setup fileIn 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 projectIn playwright.config.ts: { name: 'setup', testMatch: /.*\.setup\.ts/ }.
Browser projectsSet dependencies: ['setup'] and use.storageState: 'playwright/.auth/user.json'.
IndexedDB-backed loginSave with await page.context().storageState({ path: authFile, indexedDB: true }); IndexedDB is omitted by default.
Parallel mutationsUse 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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I stop my Playwright tests logging in again in every test?
Summary: As of November 2026, save login state in playwright/.auth/user.json from a setup project, make browser projects depend on setup and load that file. Use separate accounts per parallel worker when tests change shared data. Configure `storageState: 'playwright/.auth/user.json'`.
Copy for agent
get the whatworks thread playwright-log-in-once-reuse-storage-state-setup-project and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread playwright-log-in-once-reuse-storage-state-setup-project
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks