restoreState
Overview
Browser command that restores session state (cookies, local and session storages) from a file or variable.
warning
If you are using the webdriver
automation protocol, you have to provide webSocketUrl: true
in desiredCapabilities
in config browser settings. For the devtools
protocol, you don't need
additional settings.
Usage
You can restore state from file (using the path
param) or from object (using the data
param).
But if you provide both, the file will have the highest priority.
Also, you can provide cookies
, localStorage
and sessionStorage
params to restore only what you need.
Data for restore state you can get from the saveState command.
await browser.restoreState({
path: "./stateDump.json",
data: stateDump,
cookies: true,
localStorage: true,
sessionStorage: true,
});
Command Parameters
Name | Type | Description |
path | String | Path to file with state. |
data | SaveStateData | Object with state. |
cookies | Boolean | Enable restore cookies (true by default). |
localStorage | Boolean | Enable restore localStorage (true by default). |
sessionStorage | Boolean | Enable restore sessionStorage (true by default). |
cookieFilter | (cookie: Cookie) => boolean | Function for filtering cookies, receiving cookie objects, and returning boolean. |
Usage Examples
Restore state from file.
it("test", async ({ browser }) => {
await browser.url("https://github.com/gemini-testing/testplane");
await browser.restoreState({
path: "./stateDump.json",
cookieFilter: ({ domain }) => domain === ".example.com",
});
// Reload page for see auth result.
await browser.refresh();
});