guides
Test with multiple accounts
Switch between test accounts by exporting and importing session snapshots — and run one Playwright project per role.
The problem
QA regularly needs to walk the same flow as an admin, as a regular member, and as an anonymous visitor. Logging out and back in for every switch destroys state, resets whatever you were reproducing, and burns minutes each round trip — dozens of times a day.
Snapshot switching with Free
You can switch accounts in seconds today using JSON exports — the full-fidelity browser round-trip format:
- Log in as account A (say, the admin).
- Export the site’s cookies as JSON and save the file as
admin.cookies.json. - Log out, log in as account B (the member).
- Export again as
member.cookies.json. - From now on, switch accounts by importing the matching file — no login form, no 2FA prompt, just the session you saved.
Each import writes the snapshot’s cookies over the matching ones in the current store (same name, domain and path), so the site sees you as whichever account the file holds. Keep one file per role and per environment (admin.staging.cookies.json, …) and switching becomes a two-click operation.
One Playwright project per role
For automated tests, use storageState exports instead — a different format than the JSON snapshots above (the export formats reference shows exactly how they differ). Export one storageState file per logged-in role, then give each role its own Playwright project:
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
projects: [
{ name: 'admin', use: { storageState: 'auth/admin.json' } },
{ name: 'member', use: { storageState: 'auth/member.json' } },
],
});
Every test in the admin project starts pre-authenticated as the admin, every test in member as the member — no login steps in any test. The full workflow is in the Playwright storageState guide.
Where this is going
Named per-domain profiles — save and switch snapshots in one click, no files on disk — are the first planned Pro feature; encrypted sync and a CI-side CLI build on top of them. Join the waitlist to hear when they land.