log in once via playwright's api request context and reuse its storagestate in a browser context to skip ui login

domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. create a standalone APIRequestContext with playwright.request.newContext() (not tied to any page) and call the login endpoint directly with the request fixture
  2. call requestContext.storageState({ path: 'playwright/.auth/state.json' }) to persist the cookies and origin storage produced by the API login
  3. in a browser test project, configure use.storageState to point at that same file so browser.newContext() starts already authenticated
  4. verify the authenticated state by navigating directly to a protected page and asserting no redirect to a login screen occurs
  5. store the playwright/.auth directory outside version control and regenerate it via a setup project or globalSetup step

Known gotchas

Related routes

Persist browser authentication state to disk and reuse it across Playwright test runs to skip repeated login flows
playwright.dev · 5 steps · unrated
Decide between Playwright's launchPersistentContext(userDataDir) and storageState() for reusing authenticated sessions across test runs
playwright.dev · 5 steps · unrated
Launch a Playwright persistent browser context with launchPersistentContext and userDataDir to reuse a browser profile
playwright.dev · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans