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
Name | Type | Description |
path | String | Path to file where state will be saved. |
cookies | Boolean | Enable save cookies (true by default). |
localStorage | Boolean | Enable save localStorage (true by default). |
sessionStorage | Boolean | 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",
});
});