Skip to main content

saveState

Overview

Browser command that saves session state (cookies, local and session storages).

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

Command return state dump from page; it will include cookie, localStorage, and sessionStorage. But using params, you can disable some data. Also, if you provide the path param, you can get a dump in a file. After saving the state, you can use it in 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

NameTypeDescription
pathStringPath to file where state will be saved.
cookiesBooleanEnable save cookies (true by default).
localStorageBooleanEnable save localStorage (true by default).
sessionStorageBooleanEnable save sessionStorage (true by default).
cookieFilter(cookie: Cookie) => booleanFunction 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",
});
});