saveState
Overview
Browser command that saves session state (cookies, local and session storages).
Usage
This command returns a state of the page state, including cookies, localStorage, and sessionStorage. You can use parameters to exclude specific types of data if needed.
If you provide the path
parameter, the state dump will be saved to a file.
The saved state can later be restored using the restoreState command.
import type { SaveStateData } from "testplane";
const stateDump: SaveStateData = await browser.saveState({
path: "./stateDump.json",
cookies: true,
localStorage: true,
sessionStorage: true,
});
Command Parameters
Name | Type | Default | Description |
path | string | - | Path to file where state will be saved. |
cookies | boolean | true | Enable save cookies (true by default). |
localStorage | boolean | true | Enable save localStorage (true by default). |
sessionStorage | boolean | true | Enable save sessionStorage (true by default). |
cookieFilter | (cookie: Cookie) => boolean | - | Function for filtering cookies, receiving cookie objects, and returning boolean. |
Usage Examples
Save state in file.
it("test", async ({ browser }) => {
await browser.url("https://github.com/gemini-testing/testplane");
await browser.saveState({
path: "./stateDump.json",
cookieFilter: ({ domain }) => domain === ".example.com",
});
});