Chapter 55: Authentication and storage state
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
Authentication and storage state
Browser storage state can reuse authenticated sessions in tests. Save it after a successful login in a setup project, then configure dependent projects to load it. State can contain cookies and tokens that grant account access, so do not commit it. Tests that modify server-side state may need separate accounts.
How it works
Step-by-step walkthrough
- Use a dedicated test account
- Assert successful login
- Save and load state
Example
This is a focused snippet. Use it in the file or test context described in the walkthrough.
// In an authenticated setup test after login:
await page.context().storageState({ path: 'playwright/.auth/user.json' });
// In dependent project config use:
// storageState: 'playwright/.auth/user.json'Never store real credentials or authentication state in source control.
✎ Your practice task
Add playwright/.auth to .gitignore and create a setup project dependency.
Knowledge check
Why should auth state be gitignored?
🌐 Continue learning
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.