Reuse Auth State in Playwright

From the Playwright cheat sheet ยท Authentication & Storage State ยท verified Jul 2026

Reuse Auth State

Log in once and share the session across multiple tests

typescript
// auth.setup.ts โ€” runs once before all tests
import { test as setup, expect } from '@playwright/test';

const authFile = 'playwright/.auth/user.json';

setup('authenticate', async ({ page }) => {
  await page.goto('/login');
  await page.getByLabel('Email').fill('user@test.com');
  await page.getByLabel('Password').fill('password');
  await page.getByRole('button', { name: 'Log in' }).click();
  await page.waitForURL('/dashboard');
  await page.context().storageState({ path: authFile });
});
๐Ÿ’ก storageState saves cookies and localStorage โ€” tests start already logged in
โšก The setup project runs once, then all dependent projects reuse the saved auth state
๐Ÿ“Œ Add playwright/.auth/ to .gitignore โ€” auth state files contain session tokens
๐ŸŸข Use dependencies in config to ensure setup runs before authenticated test projects
authloginstorage-state
Back to the full Playwright cheat sheet