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