← Back to library
Playwrightauthadvancedv1.20+
Reuse saved auth state with test.use()
Load a saved storageState file so every test in the file starts already authenticated.
1import { test, expect } from '@playwright/test';
2
3// Apply the saved auth state to every test in this file.
4// The browser context starts pre-loaded with cookies and localStorage.
5test.use({ storageState: 'playwright/.auth/user.json' });
6
7test('accesses dashboard without going through login', async ({ page }) => {
8 // No login step — the context already carries a valid session
9 await page.goto('/dashboard');
10 await expect(page.getByTestId('user-menu')).toBeVisible();
11});
12
13test('accesses settings page directly', async ({ page }) => {
14 await page.goto('/settings');
15 await expect(page.getByRole('heading', { name: 'Settings' })).toBeVisible();
16});#storageState#test.use#reuse session#skip login