From 7e531b073bab84b14c9f37c38247f2908a5590d6 Mon Sep 17 00:00:00 2001 From: rocketraccoon Date: Wed, 24 Sep 2025 16:53:49 +0700 Subject: [PATCH] feat(testplane): docs for saveState and restoreState --- docs/commands/browser/restoreState.mdx | 47 +++++++++++++++++++ docs/commands/browser/saveState.mdx | 47 +++++++++++++++++++ .../current/commands/browser/restoreState.mdx | 47 +++++++++++++++++++ .../current/commands/browser/saveState.mdx | 47 +++++++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 docs/commands/browser/restoreState.mdx create mode 100644 docs/commands/browser/saveState.mdx create mode 100644 i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx create mode 100644 i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx diff --git a/docs/commands/browser/restoreState.mdx b/docs/commands/browser/restoreState.mdx new file mode 100644 index 0000000..372899f --- /dev/null +++ b/docs/commands/browser/restoreState.mdx @@ -0,0 +1,47 @@ +# restoreState + +## Overview {#overview} + +Browser command that restore session state (cookies, local and session storages) from file or variable. + + + If you are using `webdriver` automation protocol you have to provide `webSocketUrl: true` in `desiredCapabilities` in config browser settings. + For `devtools` protocol don't need additional settings. + + +## Usage {#usage} + +You can restore state from file (using `path` param) or from object (using `data` param) +But if you provide both, file have a highest priority. +Also you can provide `cookies`, `localStorage` and `sessionStorage` params for restore only that what you need. +Data for restore state you can get from [saveState](../saveState) command. + +```typescript +await browser.restoreState({ + path: './stateDump.json', + data: stateDump, + cookies: true, + localStorage: true, + sessionStorage: true, +}); +``` + +## Usage Examples {#examples} + +Restore state from file +```typescript +it("test", async ({ browser }) => { + await browser.url("https://github.com/gemini-testing/testplane"); + + await browser.restoreState({ + path: './stateDump.json', + }); + + // Reload page for see auth result. + await browser.refresh(); +}); +``` + +## Related Commands {#related} + +- [saveState](../saveState) diff --git a/docs/commands/browser/saveState.mdx b/docs/commands/browser/saveState.mdx new file mode 100644 index 0000000..e52579f --- /dev/null +++ b/docs/commands/browser/saveState.mdx @@ -0,0 +1,47 @@ +import Admonition from "@theme/Admonition"; + +# saveState + +## Overview {#overview} + +Browser command that save session state (cookies, local and session storages). + + + If you are using `webdriver` automation protocol you have to provide `webSocketUrl: true` in `desiredCapabilities` in config browser settings. + For `devtools` protocol don't need additional settings. + + +## Usage {#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 `path` param you can get dump in file. +After save state you can use it in [restoreState](../restoreState) command. + +```typescript +import type { SaveStateData } from "testplane"; + +const stateDump: SaveStateData = await browser.saveState({ + path: './stateDump.json', + cookies: true, + localStorage: true, + sessionStorage: true, +}); +``` + +## Usage Examples {#examples} + +Save state in file +```typescript +it("test", async ({ browser }) => { + await browser.url("https://github.com/gemini-testing/testplane"); + + await browser.saveState({ + path: './stateDump.json', + }); +}); +``` + +## Related Commands {#related} + +- [restoreState](../restoreState) diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx new file mode 100644 index 0000000..758c7ea --- /dev/null +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx @@ -0,0 +1,47 @@ +# restoreState + +## Обзор {#overview} + +Команда для восстановления данных (cookies, local and session storages) из файла или объекта. + + + Если вы используете `webdriver` automation protocol вы должны установить `webSocketUrl: true` в `desiredCapabilities` для браузера в конфиге. + Для `devtools` protocol не нужно дополнительных настроек. + + +## Использование {#usage} + +Вы можете восстановить данные из файла (используя параметр `path`) или из объекта (используя параметр`data`) +Но если вы укажете оба параметра то данные восстановятся из файла. +Так же вы можете указать параметры `cookies`, `localStorage` и `sessionStorage` что бы восстановить только нуд=жные данные. +Данные для восстановления вы моежете получить из команды [saveState](../saveState). + +```typescript +await browser.restoreState({ + path: './stateDump.json', + data: stateDump, + cookies: true, + localStorage: true, + sessionStorage: true, +}); +``` + +## Примеры использования {#examples} + +Восстановление данных из файла. +```typescript +it("test", async ({ browser }) => { + await browser.url("https://github.com/gemini-testing/testplane"); + + await browser.restoreState({ + path: './stateDump.json', + }); + + // Reload page for see auth result. + await browser.refresh(); +}); +``` + +## Связанные команды {#related} + +- [saveState](../saveState) diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx new file mode 100644 index 0000000..7a81fc0 --- /dev/null +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx @@ -0,0 +1,47 @@ +import Admonition from "@theme/Admonition"; + +# saveState + +## Обзор {#overview} + +Команда для сохранения состояния страницы (cookies, local и session storages). + + + Если вы используете `webdriver` automation protocol вы должны установить `webSocketUrl: true` в `desiredCapabilities` для браузера в конфиге. + Для `devtools` protocol не нужно дополнительных настроек. + + +## Использование {#usage} + +Команда вернёт объект включающий cookie, localStorage и sessionStorage. +Используя параметры вы можете выключить сохранение отдельных данных. +Так же вы можете указать параметр `path` и получить файл с данными. +После сохранения вы можете использовать результат в команде [restoreState](../restoreState). + +```typescript +import type { SaveStateData } from "testplane"; + +const stateDump: SaveStateData = await browser.saveState({ + path: './stateDump.json', + cookies: true, + localStorage: true, + sessionStorage: true, +}); +``` + +## Примеры использования {#examples} + +Сохранение данных в файл. +```typescript +it("test", async ({ browser }) => { + await browser.url("https://github.com/gemini-testing/testplane"); + + await browser.saveState({ + path: './stateDump.json', + }); +}); +``` + +## Связанные команды {#related} + +- [restoreState](../restoreState)