Skip to navigation

loadState

The loadState action loads cookies and localStorage from a state file into the open site. The file comes from saveState, or from Playwright’s storageState. For the whole pattern, see Sign in once and reuse the session.

For comprehensive options, see the loadState reference.

What it loads

loadState applies only what fits the open page:

  • the cookies whose domain is the open host or a parent of it;
  • the localStorage entries saved for the open origin.

Open the site with goTo before loadState. Then goTo again, so the app reads the loaded state:

{
"steps": [
{ "goTo": "https://app.example.com" },
{ "loadState": "auth.json" },
{ "goTo": "https://app.example.com/billing" }
]
}

Formats

String format

A path ending in .json. A relative path resolves against outputDir, where saveState writes by default.

{
"loadState": "auth.json"
}

Object format

{
"loadState": {
"path": "auth.json",
"directory": "../.auth"
}
}
FieldTypeDescriptionDefault
pathstringRequired. File to read, ending in .json. A relative path resolves against directory, or against outputDir when directory is omitted.
directorystringDirectory that holds the file. A relative directory resolves against the spec file.outputDir

Outputs

OutputDescription
pathAbsolute path of the loaded file.
cookiesNumber of cookies applied.
localStorageNumber of localStorage entries applied.

Failures

MessageFix
Couldn't load state: `/abs/auth.json` doesn't exist.Check path and directory, and that saveState ran first.
Couldn't load state: `/abs/auth.json` isn't a valid state file.Point path at a file from saveState or Playwright’s storageState.
Couldn't load state: no site is open. Use `goTo` first.Add a goTo to the site before loadState.
Couldn't load state: `/abs/auth.json` has no data for `https://app.example.com`. Use `goTo` to open that site first.Open the site the file was saved from.
Couldn't load state: the page left `https://app.example.com` before its state was restored.The page redirected during the load. Wait for it to settle, for example with a find, before loadState.