Skip to main content

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

NameTypeDefaultDescription
pathstring-Path to file where state will be saved.
cookiesbooleantrueEnable save cookies (true by default).
localStoragebooleantrueEnable save localStorage (true by default).
sessionStoragebooleantrueEnable 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",
});
});