Playwright · Reliable end-to-end tests
What is storage state and what does it capture?
Short answer
Storage state is a JSON snapshot of a context's cookies and localStorage origins. You can save it and load it into a new context to start already signed in.
Storage state is how Playwright moves a session between contexts. It is deliberately narrower than a full browser profile: it captures cookies and localStorage, but not sessionStorage, IndexedDB or in-memory application state.
await page.context().storageState({ path: "auth.json" });
const context = await browser.newContext({ storageState: "auth.json" });
const page = await context.newPage();
await page.goto("/dashboard");What is included
- Cookies with their domain, path, expiry and flags
- localStorage entries grouped by origin
- Nothing from sessionStorage, which is scoped to a single tab session
- No IndexedDB, cache storage or service worker state
- No in-memory state such as a Redux store or a JavaScript variable
If an app stores its token in localStorage, storage state is enough. If it keeps auth only in memory and rehydrates through a refresh token cookie, the cookie is enough. If it depends on sessionStorage or IndexedDB, you need a setup step in each context or an application test hook.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Does storage state include sessionStorage?
- 2How do you reuse state across projects?
- 3What if the app keeps the token in IndexedDB?
- 4Why should the state file be treated as a secret?
Say it in the interview
Storage state is a JSON snapshot of cookies and localStorage for a context. I save it after login and pass it to newContext or to the use block so tests start signed in. It does not include sessionStorage, IndexedDB or in-memory state, so an app that relies on those needs a different setup. Because it can contain live session cookies, I treat the file as a secret.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Playwright mock interview and get scored feedback on depth, clarity and confidence.