saveState
The saveState action saves the open site’s cookies and localStorage to a JSON file. Load the file in a later test with loadState, so you sign in once instead of in every test. For the whole pattern, see Sign in once and reuse the session.
The file uses Playwright’s storageState format, so a file Playwright wrote works with loadState, and Playwright can read a file saveState wrote.
Secrets in output: A state file holds real session cookies and tokens, because loadState reads them back. It isn’t masked, and it works like a password. Add its folder (directory, or outputDir by default) to .gitignore, and leave it out of uploaded CI artifacts. See Keep secrets out of logs, reports, and captures.
For comprehensive options, see the
saveStatereference.
What it saves
- Every cookie the browser exposes for the open site.
- The open origin’s
localStorage.
Open the site with goTo and sign in first. One saveState captures one site, because the browser only exposes the open site’s cookies and storage. sessionStorage isn’t saved.
Formats
String format
A path ending in .json. A relative path resolves against outputDir. It doesn’t replace an existing file.