From 7e531b073bab84b14c9f37c38247f2908a5590d6 Mon Sep 17 00:00:00 2001 From: rocketraccoon Date: Wed, 24 Sep 2025 16:53:49 +0700 Subject: [PATCH 1/9] 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) From 5f69c27ca09eeab2a9812706c72af1828465c473 Mon Sep 17 00:00:00 2001 From: rocketraccoon Date: Wed, 15 Oct 2025 12:47:33 +0700 Subject: [PATCH 2/9] feat(testplane): Fixed --- docs/commands/browser/restoreState.mdx | 32 ++++++++++++++----- docs/commands/browser/saveState.mdx | 31 +++++++++++++----- .../current/commands/browser/restoreState.mdx | 20 ++++++++++-- .../current/commands/browser/saveState.mdx | 16 ++++++++++ 4 files changed, 81 insertions(+), 18 deletions(-) diff --git a/docs/commands/browser/restoreState.mdx b/docs/commands/browser/restoreState.mdx index 372899f..4f08b80 100644 --- a/docs/commands/browser/restoreState.mdx +++ b/docs/commands/browser/restoreState.mdx @@ -2,19 +2,19 @@ ## Overview {#overview} -Browser command that restore session state (cookies, local and session storages) from file or variable. +Browser command that restores session state (cookies, local and session storages) from a 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. + 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 {#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. +You can restore state from file (using the `path` param) or from object (using the `data` param). +But if you provide both, the file will have the highest priority. +Also, you can provide `cookies`, `localStorage` and `sessionStorage` params to restore only what you need. +Data for restore state you can get from the [saveState](../saveState) command. ```typescript await browser.restoreState({ @@ -26,9 +26,25 @@ await browser.restoreState({ }); ``` +## Command Parameters {#parameters} + + + + + + + + + + + + + +
**Name****Type****Description**
pathStringPath to file with state.
dataSaveStateDataObject with state.
cookiesBooleanEnable restore cookies (true by default).
localStorageBooleanEnable restore localStorage (true by default).
sessionStorageBooleanEnable restore sessionStorage (true by default).
+ ## Usage Examples {#examples} -Restore state from file +Restore state from file. ```typescript it("test", async ({ browser }) => { await browser.url("https://github.com/gemini-testing/testplane"); diff --git a/docs/commands/browser/saveState.mdx b/docs/commands/browser/saveState.mdx index e52579f..e98f90a 100644 --- a/docs/commands/browser/saveState.mdx +++ b/docs/commands/browser/saveState.mdx @@ -4,19 +4,19 @@ import Admonition from "@theme/Admonition"; ## Overview {#overview} -Browser command that save session state (cookies, local and session storages). +Browser command that saves 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. + 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 {#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. +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](../restoreState) command. ```typescript import type { SaveStateData } from "testplane"; @@ -29,9 +29,24 @@ const stateDump: SaveStateData = await browser.saveState({ }); ``` +## Command Parameters {#parameters} + + + + + + + + + + + + +
**Name****Type****Description**
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).
+ ## Usage Examples {#examples} -Save state in file +Save state in file. ```typescript it("test", async ({ browser }) => { await browser.url("https://github.com/gemini-testing/testplane"); 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 index 758c7ea..e075507 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx @@ -13,8 +13,24 @@ Вы можете восстановить данные из файла (используя параметр `path`) или из объекта (используя параметр`data`) Но если вы укажете оба параметра то данные восстановятся из файла. -Так же вы можете указать параметры `cookies`, `localStorage` и `sessionStorage` что бы восстановить только нуд=жные данные. -Данные для восстановления вы моежете получить из команды [saveState](../saveState). +Так же вы можете указать параметры `cookies`, `localStorage` и `sessionStorage` что бы восстановить только нужные данные. +Данные для восстановления вы можете получить из команды [saveState](../saveState). + +## Параметры команды {#parameters} + + + + + + + + + + + + + +
**Имя****Тип****Описание**
pathStringПуть к файлу с данными.
dataSaveStateDataОбъект с данными.
cookiesBooleanВключить восстановление кук (true по умолчанию).
localStorageBooleanВключить восстановление localStorage (true по умолчанию).
sessionStorageBooleanВключить восстановление sessionStorage (true по умолчанию).
```typescript await browser.restoreState({ 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 index 7a81fc0..7337b42 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx @@ -29,6 +29,22 @@ const stateDump: SaveStateData = await browser.saveState({ }); ``` +## Параметры команды {#parameters} + + + + + + + + + + + + +
**Имя****Тип****Описание**
pathStringПуть где будет сохранён файл с данными.
cookiesBooleanВключить сохранение кук (true по умолчанию).
localStorageBooleanВключить сохранение localStorage (true по умолчанию).
sessionStorageBooleanВключить сохранение sessionStorage (true по умолчанию).
+ + ## Примеры использования {#examples} Сохранение данных в файл. From a21253e57f35ff8414b4940320fa0899cfd1afe8 Mon Sep 17 00:00:00 2001 From: rocketraccoon Date: Wed, 15 Oct 2025 13:39:35 +0700 Subject: [PATCH 3/9] feat(testplane): add afterAll/beforeAll docs --- docs/command-line/index.mdx | 1 + docs/commands/browser/restoreState.mdx | 11 ++-- docs/commands/browser/saveState.mdx | 11 ++-- docs/config/after-all.mdx | 54 +++++++++++++++++++ docs/config/before-all.mdx | 54 +++++++++++++++++++ docs/reference/testplane-standalone-api.mdx | 2 +- .../current/command-line/index.mdx | 1 + .../current/commands/browser/restoreState.mdx | 11 ++-- .../current/commands/browser/saveState.mdx | 12 +++-- .../current/config/after-all.mdx | 54 +++++++++++++++++++ .../current/config/before-all.mdx | 54 +++++++++++++++++++ .../reference/testplane-standalone-api.mdx | 2 +- 12 files changed, 248 insertions(+), 19 deletions(-) create mode 100644 docs/config/after-all.mdx create mode 100644 docs/config/before-all.mdx create mode 100644 i18n/ru/docusaurus-plugin-content-docs/current/config/after-all.mdx create mode 100644 i18n/ru/docusaurus-plugin-content-docs/current/config/before-all.mdx diff --git a/docs/command-line/index.mdx b/docs/command-line/index.mdx index a3db8ed..9e95ad9 100644 --- a/docs/command-line/index.mdx +++ b/docs/command-line/index.mdx @@ -192,6 +192,7 @@ testplane --repl --grep 'my test name' --browser chrome - `--keep-browser-on-fail` - the same as the `--keep-browser` option, but the browser will only remain open if the tests fail. Example of console output with connection information to the browser: + ``` [15:44:38 +0700] Testplane run has finished, but the browser won't be closed, because you passed the --keep-browser argument. [15:44:38 +0700] You may attach to this browser using the following capabilities: diff --git a/docs/commands/browser/restoreState.mdx b/docs/commands/browser/restoreState.mdx index 4f08b80..7c50544 100644 --- a/docs/commands/browser/restoreState.mdx +++ b/docs/commands/browser/restoreState.mdx @@ -5,8 +5,9 @@ Browser command that restores session state (cookies, local and session storages) from a file or variable. - 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. + 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 {#usage} @@ -18,7 +19,7 @@ Data for restore state you can get from the [saveState](../saveState) command. ```typescript await browser.restoreState({ - path: './stateDump.json', + path: "./stateDump.json", data: stateDump, cookies: true, localStorage: true, @@ -40,17 +41,19 @@ await browser.restoreState({ sessionStorageBooleanEnable restore sessionStorage (true by default). + ## 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', + path: "./stateDump.json", }); // Reload page for see auth result. diff --git a/docs/commands/browser/saveState.mdx b/docs/commands/browser/saveState.mdx index e98f90a..861dd97 100644 --- a/docs/commands/browser/saveState.mdx +++ b/docs/commands/browser/saveState.mdx @@ -7,8 +7,9 @@ import Admonition from "@theme/Admonition"; Browser command that saves session state (cookies, local and session storages). - 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. + 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 {#usage} @@ -22,7 +23,7 @@ After saving the state, you can use it in the [restoreState](../restoreState) co import type { SaveStateData } from "testplane"; const stateDump: SaveStateData = await browser.saveState({ - path: './stateDump.json', + path: "./stateDump.json", cookies: true, localStorage: true, sessionStorage: true, @@ -42,17 +43,19 @@ const stateDump: SaveStateData = await browser.saveState({ sessionStorageBooleanEnable save sessionStorage (true by default). + ## 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', + path: "./stateDump.json", }); }); ``` diff --git a/docs/config/after-all.mdx b/docs/config/after-all.mdx new file mode 100644 index 0000000..5eacb73 --- /dev/null +++ b/docs/config/after-all.mdx @@ -0,0 +1,54 @@ +# afterAll + +## Overview {#overview} + +This parameter is a hook. The function specified for this parameter will be automatically called after tests are completed. + +The context of the function is the Testplane config. Also function receive config in arguments. + +## Usage Example {#example} + +Here is an example of suing this hook for logout. + +```typescript title="testplane.config.ts" +import { launchBrowser } from "testplane/unstable"; + +export default { + // ... + browsers: { + chrome: { + headless: true, + desiredCapabilities: { + webSocketUrl: true, + browserName: "chrome", + }, + }, + firefox: { + headless: true, + desiredCapabilities: { + webSocketUrl: true, + browserName: "firefox", + }, + }, + }, + afterAll: async () => { + // launch a new browser with existing config + const browser = await launchBrowser(this.config.browsers.chrome); + + await browser.url("https://example.com"); + + // login using saved state + await browser.restoreState({ + path: "./dump.json", + }); + + // do logout things (press logout button etc.) + + await browser.deleteSession(); + }, +}; +``` + +## Related {#related} + +- [beforeAll](../before-all) diff --git a/docs/config/before-all.mdx b/docs/config/before-all.mdx new file mode 100644 index 0000000..4666a42 --- /dev/null +++ b/docs/config/before-all.mdx @@ -0,0 +1,54 @@ +# beforeAll + +## Overview {#overview} + +This parameter is a hook. The function specified for this parameter will be automatically called before tests running. + +The context of the function is the Testplane config. Also function receive config in arguments. + +## Usage Example {#example} + +Here is an example of using this hook for logging in and getting session data for use in tests. + +```typescript title="testplane.config.ts" +import { launchBrowser } from "testplane/unstable"; + +export default { + // ... + browsers: { + chrome: { + headless: true, + desiredCapabilities: { + webSocketUrl: true, + browserName: "chrome", + }, + }, + firefox: { + headless: true, + desiredCapabilities: { + webSocketUrl: true, + browserName: "firefox", + }, + }, + }, + beforeAll: async () => { + // launch a new browser with existing config + const browser = await launchBrowser(this.config.browsers.chrome); + + await browser.url("https://example.com"); + + // do login things, type username/password etc. + + // save dump with state (cookies, localStorage) for using in tests + await browser.saveState({ + path: "./dump.json", + }); + + await browser.deleteSession(); + }, +}; +``` + +## Related {#related} + +- [afterAll](../after-all) diff --git a/docs/reference/testplane-standalone-api.mdx b/docs/reference/testplane-standalone-api.mdx index 6bf2d9e..2c56fa6 100644 --- a/docs/reference/testplane-standalone-api.mdx +++ b/docs/reference/testplane-standalone-api.mdx @@ -18,7 +18,7 @@ import { launchBrowser } from "testplane/unstable"; // Launch a new browser with the given settings const browser = await launchBrowser({ desiredCapabilities: { - browserName: 'chrome', + browserName: "chrome", }, headless: false, }); diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/command-line/index.mdx b/i18n/ru/docusaurus-plugin-content-docs/current/command-line/index.mdx index 62a14bc..923e794 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/command-line/index.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/command-line/index.mdx @@ -193,6 +193,7 @@ testplane --repl --grep 'my test name' --browser chrome - `--keep-browser-on-fail` - то же, что и опция `--keep-browser`, только браузер останется только в том случае, если тесты завершатся неуспешно Пример вывода в консоли c информацией для подключения к браузеру + ``` [15:44:38 +0700] Testplane run has finished, but the browser won't be closed, because you passed the --keep-browser argument. [15:44:38 +0700] You may attach to this browser using the following capabilities: 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 index e075507..e0ca15d 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx @@ -5,8 +5,9 @@ Команда для восстановления данных (cookies, local and session storages) из файла или объекта. - Если вы используете `webdriver` automation protocol вы должны установить `webSocketUrl: true` в `desiredCapabilities` для браузера в конфиге. - Для `devtools` protocol не нужно дополнительных настроек. + Если вы используете `webdriver` automation protocol вы должны установить `webSocketUrl: true` в + `desiredCapabilities` для браузера в конфиге. Для `devtools` protocol не нужно дополнительных + настроек. ## Использование {#usage} @@ -30,11 +31,12 @@ sessionStorageBooleanВключить восстановление sessionStorage (true по умолчанию). + ```typescript await browser.restoreState({ - path: './stateDump.json', + path: "./stateDump.json", data: stateDump, cookies: true, localStorage: true, @@ -45,12 +47,13 @@ await browser.restoreState({ ## Примеры использования {#examples} Восстановление данных из файла. + ```typescript it("test", async ({ browser }) => { await browser.url("https://github.com/gemini-testing/testplane"); await browser.restoreState({ - path: './stateDump.json', + path: "./stateDump.json", }); // Reload page for see auth result. 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 index 7337b42..f75b32e 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx @@ -7,8 +7,9 @@ import Admonition from "@theme/Admonition"; Команда для сохранения состояния страницы (cookies, local и session storages). - Если вы используете `webdriver` automation protocol вы должны установить `webSocketUrl: true` в `desiredCapabilities` для браузера в конфиге. - Для `devtools` protocol не нужно дополнительных настроек. + Если вы используете `webdriver` automation protocol вы должны установить `webSocketUrl: true` в + `desiredCapabilities` для браузера в конфиге. Для `devtools` protocol не нужно дополнительных + настроек. ## Использование {#usage} @@ -22,7 +23,7 @@ import Admonition from "@theme/Admonition"; import type { SaveStateData } from "testplane"; const stateDump: SaveStateData = await browser.saveState({ - path: './stateDump.json', + path: "./stateDump.json", cookies: true, localStorage: true, sessionStorage: true, @@ -42,18 +43,19 @@ const stateDump: SaveStateData = await browser.saveState({ sessionStorageBooleanВключить сохранение sessionStorage (true по умолчанию). - + ## Примеры использования {#examples} Сохранение данных в файл. + ```typescript it("test", async ({ browser }) => { await browser.url("https://github.com/gemini-testing/testplane"); await browser.saveState({ - path: './stateDump.json', + path: "./stateDump.json", }); }); ``` diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/config/after-all.mdx b/i18n/ru/docusaurus-plugin-content-docs/current/config/after-all.mdx new file mode 100644 index 0000000..1801750 --- /dev/null +++ b/i18n/ru/docusaurus-plugin-content-docs/current/config/after-all.mdx @@ -0,0 +1,54 @@ +# afterAll + +## Обзор {#overview} + +Данный параметр является хуком. Функция, заданная для данного параметра, будет автоматически вызвана после прохождения тестов. + +Контекстом функции является конфиг Testplane. Так же функция принимает конфиг в аргументе. + +## Пример использования {#example} + +Пример разлогина после выполнения тестов. + +```typescript title="testplane.config.ts" +import { launchBrowser } from "testplane/unstable"; + +export default { + // ... + browsers: { + chrome: { + headless: true, + desiredCapabilities: { + webSocketUrl: true, + browserName: "chrome", + }, + }, + firefox: { + headless: true, + desiredCapabilities: { + webSocketUrl: true, + browserName: "firefox", + }, + }, + }, + afterAll: async () => { + // launch a new browser with existing config + const browser = await launchBrowser(this.config.browsers.chrome); + + await browser.url("https://example.com"); + + // login using saved state + await browser.restoreState({ + path: "./dump.json", + }); + + // do logout things (press logout button etc.) + + await browser.deleteSession(); + }, +}; +``` + +## Связанные хуки {#related} + +- [beforeAll](../before-all) diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/config/before-all.mdx b/i18n/ru/docusaurus-plugin-content-docs/current/config/before-all.mdx new file mode 100644 index 0000000..5daf88f --- /dev/null +++ b/i18n/ru/docusaurus-plugin-content-docs/current/config/before-all.mdx @@ -0,0 +1,54 @@ +# beforeAll + +## Обзор {#overview} + +Данный параметр является хуком. Функция, заданная для данного параметра, будет автоматически вызвана до запуска тестов. + +Контекстом функции является конфиг Testplane. Так же функция принимает конфиг в аргументе. + +## Пример использования {#example} + +Пример логина и сохранения стейта сессии (куки, localStorage) для его последующего использования в тестах. + +```typescript title="testplane.config.ts" +import { launchBrowser } from "testplane/unstable"; + +export default { + // ... + browsers: { + chrome: { + headless: true, + desiredCapabilities: { + webSocketUrl: true, + browserName: "chrome", + }, + }, + firefox: { + headless: true, + desiredCapabilities: { + webSocketUrl: true, + browserName: "firefox", + }, + }, + }, + beforeAll: async () => { + // launch a new browser with existing config + const browser = await launchBrowser(this.config.browsers.chrome); + + await browser.url("https://example.com"); + + // do login things, type username/password etc. + + // save dump with state (cookies, localStorage) for using in tests + await browser.saveState({ + path: "./dump.json", + }); + + await browser.deleteSession(); + }, +}; +``` + +## Связанные хуки {#related} + +- [afterAll](../after-all) diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/reference/testplane-standalone-api.mdx b/i18n/ru/docusaurus-plugin-content-docs/current/reference/testplane-standalone-api.mdx index f5707a0..0797435 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/reference/testplane-standalone-api.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/reference/testplane-standalone-api.mdx @@ -18,7 +18,7 @@ import { launchBrowser } from "testplane/unstable"; // Запуск браузера с необходимыми параметрами const browser = await launchBrowser({ desiredCapabilities: { - browserName: 'chrome', + browserName: "chrome", }, headless: false, }); From ba553af9137c23dea7020868f67b6a8e0c25835c Mon Sep 17 00:00:00 2001 From: rocketraccoon Date: Wed, 15 Oct 2025 13:48:30 +0700 Subject: [PATCH 4/9] feat(testplane): add cookieFilter --- docs/commands/browser/restoreState.mdx | 2 ++ docs/commands/browser/saveState.mdx | 2 ++ .../current/commands/browser/restoreState.mdx | 2 ++ .../current/commands/browser/saveState.mdx | 2 ++ 4 files changed, 8 insertions(+) diff --git a/docs/commands/browser/restoreState.mdx b/docs/commands/browser/restoreState.mdx index 7c50544..3b1765f 100644 --- a/docs/commands/browser/restoreState.mdx +++ b/docs/commands/browser/restoreState.mdx @@ -39,6 +39,7 @@ await browser.restoreState({ cookiesBooleanEnable restore cookies (true by default). localStorageBooleanEnable restore localStorage (true by default). sessionStorageBooleanEnable restore sessionStorage (true by default). + cookieFilter(cookie: Cookie) => booleanFunction for filtering cookies, receiving cookie objects, and returning boolean. @@ -54,6 +55,7 @@ it("test", async ({ browser }) => { await browser.restoreState({ path: "./stateDump.json", + cookieFilter: ({ domain }) => domain === ".example.com", }); // Reload page for see auth result. diff --git a/docs/commands/browser/saveState.mdx b/docs/commands/browser/saveState.mdx index 861dd97..30f6605 100644 --- a/docs/commands/browser/saveState.mdx +++ b/docs/commands/browser/saveState.mdx @@ -41,6 +41,7 @@ const stateDump: SaveStateData = await browser.saveState({ 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. @@ -56,6 +57,7 @@ it("test", async ({ browser }) => { await browser.saveState({ path: "./stateDump.json", + cookieFilter: ({ domain }) => domain === ".example.com", }); }); ``` 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 index e0ca15d..3f2f1ed 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx @@ -29,6 +29,7 @@ cookiesBooleanВключить восстановление кук (true по умолчанию). localStorageBooleanВключить восстановление localStorage (true по умолчанию). sessionStorageBooleanВключить восстановление sessionStorage (true по умолчанию). + cookieFilter(cookie: Cookie) => booleanФункция для фильтрации кук, принимает объект куки и возвращает boolean. @@ -54,6 +55,7 @@ it("test", async ({ browser }) => { await browser.restoreState({ path: "./stateDump.json", + cookieFilter: ({ domain }) => domain === ".example.com", }); // Reload page for see auth result. 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 index f75b32e..61c69c2 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx @@ -41,6 +41,7 @@ const stateDump: SaveStateData = await browser.saveState({ cookiesBooleanВключить сохранение кук (true по умолчанию). localStorageBooleanВключить сохранение localStorage (true по умолчанию). sessionStorageBooleanВключить сохранение sessionStorage (true по умолчанию). + cookieFilter(cookie: Cookie) => booleanФункция для фильтрации кук, принимает объект куки и возвращает boolean. @@ -56,6 +57,7 @@ it("test", async ({ browser }) => { await browser.saveState({ path: "./stateDump.json", + cookieFilter: ({ domain }) => domain === ".example.com", }); }); ``` From c18d65ef4003841d24de69d56d3a03fea637c49f Mon Sep 17 00:00:00 2001 From: rocketraccoon Date: Wed, 15 Oct 2025 13:57:00 +0700 Subject: [PATCH 5/9] feat(testplane): fixed --- docs/commands/browser/restoreState.mdx | 2 ++ .../current/commands/browser/restoreState.mdx | 2 ++ 2 files changed, 4 insertions(+) diff --git a/docs/commands/browser/restoreState.mdx b/docs/commands/browser/restoreState.mdx index 3b1765f..ed2075c 100644 --- a/docs/commands/browser/restoreState.mdx +++ b/docs/commands/browser/restoreState.mdx @@ -1,3 +1,5 @@ +import Admonition from "@theme/Admonition"; + # restoreState ## Overview {#overview} 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 index 3f2f1ed..0bebdd2 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx @@ -1,3 +1,5 @@ +import Admonition from "@theme/Admonition"; + # restoreState ## Обзор {#overview} From 7e48133c77d7a8ee26fa59d9661de60c37b4d098 Mon Sep 17 00:00:00 2001 From: rocketraccoon Date: Tue, 21 Oct 2025 16:32:54 +0700 Subject: [PATCH 6/9] feat(testplane): fixes --- docs/commands/browser/restoreState.mdx | 31 +++++++---------- docs/commands/browser/saveState.mdx | 27 ++++++--------- docs/config/after-all.mdx | 34 ++----------------- .../current/commands/browser/restoreState.mdx | 31 +++++++---------- .../current/commands/browser/saveState.mdx | 27 ++++++--------- .../current/config/after-all.mdx | 34 ++----------------- 6 files changed, 52 insertions(+), 132 deletions(-) diff --git a/docs/commands/browser/restoreState.mdx b/docs/commands/browser/restoreState.mdx index ed2075c..4435ae5 100644 --- a/docs/commands/browser/restoreState.mdx +++ b/docs/commands/browser/restoreState.mdx @@ -1,23 +1,18 @@ -import Admonition from "@theme/Admonition"; - # restoreState ## Overview {#overview} Browser command that restores session state (cookies, local and session storages) from a file or variable. - - 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 {#usage} -You can restore state from file (using the `path` param) or from object (using the `data` param). -But if you provide both, the file will have the highest priority. -Also, you can provide `cookies`, `localStorage` and `sessionStorage` params to restore only what you need. -Data for restore state you can get from the [saveState](../saveState) command. +You can restore the browser state from either a file (using the `path` parameter) or directly from an object (using the `data` parameter). + +**Important:** If you provide both `path` and `data` parameters, the file specified in `path` will take priority. + +You can optionally specify which storage types to restore using the `cookies`, `localStorage`, and `sessionStorage` parameters. This allows you to restore only the specific data you need. + +The state data for restoration can be obtained from the [saveState](../saveState) command. ```typescript await browser.restoreState({ @@ -36,12 +31,12 @@ await browser.restoreState({ **Name****Type****Description** - pathStringPath to file with state. - dataSaveStateDataObject with state. - cookiesBooleanEnable restore cookies (true by default). - localStorageBooleanEnable restore localStorage (true by default). - sessionStorageBooleanEnable restore sessionStorage (true by default). - cookieFilter(cookie: Cookie) => booleanFunction for filtering cookies, receiving cookie objects, and returning boolean. + path`string`Path to file with state. + data`SaveStateData`Object with state. + cookies`boolean`Enable restore cookies (true by default). + localStorage`boolean`Enable restore localStorage (true by default). + sessionStorage`boolean`Enable restore sessionStorage (true by default). + cookieFilter`(cookie: Cookie) => boolean`Function for filtering cookies, receiving cookie objects, and returning boolean. diff --git a/docs/commands/browser/saveState.mdx b/docs/commands/browser/saveState.mdx index 30f6605..a700cb9 100644 --- a/docs/commands/browser/saveState.mdx +++ b/docs/commands/browser/saveState.mdx @@ -1,23 +1,16 @@ -import Admonition from "@theme/Admonition"; - # saveState ## Overview {#overview} Browser command that saves session state (cookies, local and session storages). - - 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 {#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](../restoreState) command. +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](../restoreState) command. ```typescript import type { SaveStateData } from "testplane"; @@ -37,11 +30,11 @@ const stateDump: SaveStateData = await browser.saveState({ **Name****Type****Description** - 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. + 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. diff --git a/docs/config/after-all.mdx b/docs/config/after-all.mdx index 5eacb73..fd69386 100644 --- a/docs/config/after-all.mdx +++ b/docs/config/after-all.mdx @@ -8,43 +8,15 @@ The context of the function is the Testplane config. Also function receive confi ## Usage Example {#example} -Here is an example of suing this hook for logout. +Here is an example of using this hook to remove a file with a page state. ```typescript title="testplane.config.ts" -import { launchBrowser } from "testplane/unstable"; +import * as fs from "fs"; export default { // ... - browsers: { - chrome: { - headless: true, - desiredCapabilities: { - webSocketUrl: true, - browserName: "chrome", - }, - }, - firefox: { - headless: true, - desiredCapabilities: { - webSocketUrl: true, - browserName: "firefox", - }, - }, - }, afterAll: async () => { - // launch a new browser with existing config - const browser = await launchBrowser(this.config.browsers.chrome); - - await browser.url("https://example.com"); - - // login using saved state - await browser.restoreState({ - path: "./dump.json", - }); - - // do logout things (press logout button etc.) - - await browser.deleteSession(); + await fs.unlink("./dump.json"); }, }; ``` 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 index 0bebdd2..1d4c37e 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx @@ -1,23 +1,18 @@ -import Admonition from "@theme/Admonition"; - # restoreState ## Обзор {#overview} Команда для восстановления данных (cookies, local and session storages) из файла или объекта. - - Если вы используете `webdriver` automation protocol вы должны установить `webSocketUrl: true` в - `desiredCapabilities` для браузера в конфиге. Для `devtools` protocol не нужно дополнительных - настроек. - - ## Использование {#usage} -Вы можете восстановить данные из файла (используя параметр `path`) или из объекта (используя параметр`data`) -Но если вы укажете оба параметра то данные восстановятся из файла. -Так же вы можете указать параметры `cookies`, `localStorage` и `sessionStorage` что бы восстановить только нужные данные. -Данные для восстановления вы можете получить из команды [saveState](../saveState). +Вы можете восстановить состояние браузера из файла (с помощью параметра `path`) или непосредственно из объекта (с помощью параметра `data`). + +**Важно:** Если вы указали оба параметра `path` и `data`, приоритет будет у файла, указанного в `path`. + +При необходимости вы можете указать, какие типы данных восстановить, используя параметры `cookies`, `localStorage` и `sessionStorage`. Это позволяет восстановить только те данные, которые вам нужны. + +Данные для восстановления состояния можно получить с помощью команды [saveState](../saveState). ## Параметры команды {#parameters} @@ -26,12 +21,12 @@ import Admonition from "@theme/Admonition"; **Имя****Тип****Описание** - pathStringПуть к файлу с данными. - dataSaveStateDataОбъект с данными. - cookiesBooleanВключить восстановление кук (true по умолчанию). - localStorageBooleanВключить восстановление localStorage (true по умолчанию). - sessionStorageBooleanВключить восстановление sessionStorage (true по умолчанию). - cookieFilter(cookie: Cookie) => booleanФункция для фильтрации кук, принимает объект куки и возвращает boolean. + path`string`Путь к файлу с данными. + data`SaveStateData`Объект с данными. + cookies`boolean`Включить восстановление кук (true по умолчанию). + localStorage`boolean`Включить восстановление localStorage (true по умолчанию). + sessionStorage`boolean`Включить восстановление sessionStorage (true по умолчанию). + cookieFilter`(cookie: Cookie) => boolean`Функция для фильтрации кук, принимает объект куки и возвращает boolean. 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 index 61c69c2..9e9a99a 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx @@ -1,23 +1,16 @@ -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). +Эта команда возвращает снимок состояния страницы, включая cookies, localStorage и sessionStorage. +С помощью параметров вы можете при необходимости исключить определённые типы данных. + +Если вы укажете параметр `path`, снимок состояния будет сохранён в файл. +Сохранённое состояние можно впоследствии восстановить с помощью команды [restoreState](../restoreState). ```typescript import type { SaveStateData } from "testplane"; @@ -37,11 +30,11 @@ const stateDump: SaveStateData = await browser.saveState({ **Имя****Тип****Описание** - pathStringПуть где будет сохранён файл с данными. - cookiesBooleanВключить сохранение кук (true по умолчанию). - localStorageBooleanВключить сохранение localStorage (true по умолчанию). - sessionStorageBooleanВключить сохранение sessionStorage (true по умолчанию). - cookieFilter(cookie: Cookie) => booleanФункция для фильтрации кук, принимает объект куки и возвращает boolean. + path`string`Путь где будет сохранён файл с данными. + cookies`boolean`Включить сохранение кук (true по умолчанию). + localStorage`boolean`Включить сохранение localStorage (true по умолчанию). + sessionStorage`boolean`Включить сохранение sessionStorage (true по умолчанию). + cookieFilter`(cookie: Cookie) => boolean`Функция для фильтрации кук, принимает объект куки и возвращает boolean. diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/config/after-all.mdx b/i18n/ru/docusaurus-plugin-content-docs/current/config/after-all.mdx index 1801750..045a142 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/config/after-all.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/config/after-all.mdx @@ -8,43 +8,15 @@ ## Пример использования {#example} -Пример разлогина после выполнения тестов. +Пример удаления файла с состоянием страницы после выполнения тестов. ```typescript title="testplane.config.ts" -import { launchBrowser } from "testplane/unstable"; +import * as fs from "fs"; export default { // ... - browsers: { - chrome: { - headless: true, - desiredCapabilities: { - webSocketUrl: true, - browserName: "chrome", - }, - }, - firefox: { - headless: true, - desiredCapabilities: { - webSocketUrl: true, - browserName: "firefox", - }, - }, - }, afterAll: async () => { - // launch a new browser with existing config - const browser = await launchBrowser(this.config.browsers.chrome); - - await browser.url("https://example.com"); - - // login using saved state - await browser.restoreState({ - path: "./dump.json", - }); - - // do logout things (press logout button etc.) - - await browser.deleteSession(); + fs.unlinkSync("dump.json"); }, }; ``` From fc1ed2b6a6fb2241d38046c5228e7d139b296e02 Mon Sep 17 00:00:00 2001 From: rocketraccoon Date: Tue, 21 Oct 2025 16:42:26 +0700 Subject: [PATCH 7/9] feat(testplane): fixes --- docs/commands/browser/restoreState.mdx | 53 +++++++++++++++---- docs/commands/browser/saveState.mdx | 46 +++++++++++++--- .../current/commands/browser/restoreState.mdx | 51 ++++++++++++++---- .../current/commands/browser/saveState.mdx | 44 ++++++++++++--- 4 files changed, 160 insertions(+), 34 deletions(-) diff --git a/docs/commands/browser/restoreState.mdx b/docs/commands/browser/restoreState.mdx index 4435ae5..5e8f27b 100644 --- a/docs/commands/browser/restoreState.mdx +++ b/docs/commands/browser/restoreState.mdx @@ -28,18 +28,53 @@ await browser.restoreState({ - + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -
**Name****Type****Description**
**Name****Type****Default****Description**
path`string`Path to file with state.
data`SaveStateData`Object with state.
cookies`boolean`Enable restore cookies (true by default).
localStorage`boolean`Enable restore localStorage (true by default).
sessionStorage`boolean`Enable restore sessionStorage (true by default).
cookieFilter`(cookie: Cookie) => boolean`Function for filtering cookies, receiving cookie objects, and returning boolean.
path`string``-`Path to file with state.
data`SaveStateData``-`Object with state.
cookies`boolean``true`Enable restore cookies (true by default).
localStorage`boolean``true`Enable restore localStorage (true by default).
sessionStorage`boolean``true`Enable restore sessionStorage (true by default).
cookieFilter`(cookie: Cookie) => boolean``-` + Function for filtering cookies, receiving cookie objects, and returning boolean. +
## Usage Examples {#examples} diff --git a/docs/commands/browser/saveState.mdx b/docs/commands/browser/saveState.mdx index a700cb9..b3bb1b9 100644 --- a/docs/commands/browser/saveState.mdx +++ b/docs/commands/browser/saveState.mdx @@ -27,17 +27,47 @@ const stateDump: SaveStateData = await browser.saveState({ - + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -
**Name****Type****Description**
**Name****Type****Default****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.
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 {#examples} 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 index 1d4c37e..38f2c50 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx @@ -18,18 +18,51 @@ - + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -
**Имя****Тип****Описание**
**Имя****Тип****Значение по умолчанию****Описание**
path`string`Путь к файлу с данными.
data`SaveStateData`Объект с данными.
cookies`boolean`Включить восстановление кук (true по умолчанию).
localStorage`boolean`Включить восстановление localStorage (true по умолчанию).
sessionStorage`boolean`Включить восстановление sessionStorage (true по умолчанию).
cookieFilter`(cookie: Cookie) => boolean`Функция для фильтрации кук, принимает объект куки и возвращает boolean.
path`string``-`Путь к файлу с данными.
data`SaveStateData``-`Объект с данными.
cookies`boolean``true`Включить восстановление кук (true по умолчанию).
localStorage`boolean``true`Включить восстановление localStorage (true по умолчанию).
sessionStorage`boolean``true`Включить восстановление sessionStorage (true по умолчанию).
cookieFilter`(cookie: Cookie) => boolean``-`Функция для фильтрации кук, принимает объект куки и возвращает boolean.
```typescript 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 index 9e9a99a..a610821 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx @@ -27,17 +27,45 @@ const stateDump: SaveStateData = await browser.saveState({ - + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -
**Имя****Тип****Описание**
**Имя****Тип****Значение по умолчанию****Описание**
path`string`Путь где будет сохранён файл с данными.
cookies`boolean`Включить сохранение кук (true по умолчанию).
localStorage`boolean`Включить сохранение localStorage (true по умолчанию).
sessionStorage`boolean`Включить сохранение sessionStorage (true по умолчанию).
cookieFilter`(cookie: Cookie) => boolean`Функция для фильтрации кук, принимает объект куки и возвращает boolean.
path`string``-`Путь где будет сохранён файл с данными.
cookies`boolean``екгу`Включить сохранение кук (true по умолчанию).
localStorage`boolean``екгу`Включить сохранение localStorage (true по умолчанию).
sessionStorage`boolean``екгу`Включить сохранение sessionStorage (true по умолчанию).
cookieFilter`(cookie: Cookie) => boolean``-`Функция для фильтрации кук, принимает объект куки и возвращает boolean.
## Примеры использования {#examples} From ca3ba6a9d29de85c9bd9510d519e6edb1d1b0025 Mon Sep 17 00:00:00 2001 From: rocketraccoon Date: Tue, 21 Oct 2025 17:16:49 +0700 Subject: [PATCH 8/9] feat(testplane): fixes --- docs/commands/browser/restoreState.mdx | 7 ++++++ .../current/commands/browser/restoreState.mdx | 25 +++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/docs/commands/browser/restoreState.mdx b/docs/commands/browser/restoreState.mdx index 5e8f27b..ccf6777 100644 --- a/docs/commands/browser/restoreState.mdx +++ b/docs/commands/browser/restoreState.mdx @@ -1,3 +1,5 @@ +import Admonition from "@theme/Admonition"; + # restoreState ## Overview {#overview} @@ -14,6 +16,11 @@ You can optionally specify which storage types to restore using the `cookies`, ` The state data for restoration can be obtained from the [saveState](../saveState) command. + + You must be on the exact same page from which the cookies were originally saved. You need to + navigate to the page first, use the [url](../url) command before restoring state. + + ```typescript await browser.restoreState({ path: "./stateDump.json", 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 index 38f2c50..27f3327 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx @@ -14,6 +14,21 @@ Данные для восстановления состояния можно получить с помощью команды [saveState](../saveState). + + Вы должны находиться на той же странице, с которой были сохранены cookies. Вам нужно сначала + перейти на страницу, используйте команду [url](../url) перед восстановлением состояния. + + +```typescript +await browser.restoreState({ + path: "./stateDump.json", + data: stateDump, + cookies: true, + localStorage: true, + sessionStorage: true, +}); +``` + ## Параметры команды {#parameters} @@ -65,16 +80,6 @@
-```typescript -await browser.restoreState({ - path: "./stateDump.json", - data: stateDump, - cookies: true, - localStorage: true, - sessionStorage: true, -}); -``` - ## Примеры использования {#examples} Восстановление данных из файла. From 92087adbc582c73b0ed061279719bf09b749eaa0 Mon Sep 17 00:00:00 2001 From: rocketraccoon Date: Tue, 21 Oct 2025 17:26:46 +0700 Subject: [PATCH 9/9] feat(testplane): fixes --- docs/commands/browser/restoreState.mdx | 44 ++++++++++++++++++ docs/commands/browser/saveState.mdx | 2 + .../current/commands/browser/restoreState.mdx | 46 +++++++++++++++++++ .../current/commands/browser/saveState.mdx | 2 + 4 files changed, 94 insertions(+) diff --git a/docs/commands/browser/restoreState.mdx b/docs/commands/browser/restoreState.mdx index ccf6777..8af093f 100644 --- a/docs/commands/browser/restoreState.mdx +++ b/docs/commands/browser/restoreState.mdx @@ -102,6 +102,50 @@ it("test", async ({ browser }) => { }); ``` +Example of implementing authentication in tests with saveState/restoreState and beforeAll hook. + +```typescript +import { ConfigInput, WdioBrowser } from "testplane"; +import { launchBrowser } from "testplane/unstable"; + +export default { + gridUrl: "local", + beforeAll: async ({ config }) => { + const b = await launchBrowser(config.browsers["chrome"]!); + + await b.url("https://our-site.com"); + await b.$("input.login").setValue("user@example.com"); + await b.$("input.password").setValue("password123"); + + await b.saveState({ path: "./.testplane/state.json" }); + await b.deleteSession(); + }, + sets: { + /* ... */ + }, + browsers: { + chrome: { + headless: false, + desiredCapabilities: { + browserName: "chrome", + }, + }, + }, + plugins: { + /* ... */ + "@testplane/global-hook": { + enabled: true, + beforeEach: async ({ browser }: { browser: WdioBrowser }) => { + await browser.url("https://our-site.com"); + await browser.restoreState({ path: "./.testplane/state.json" }); + }, + }, + }, +} satisfies ConfigInput; +``` + ## Related Commands {#related} - [saveState](../saveState) +- [afterAll](../../../config/after-all) +- [beforeAll](../../../config/before-all) diff --git a/docs/commands/browser/saveState.mdx b/docs/commands/browser/saveState.mdx index b3bb1b9..f808a6b 100644 --- a/docs/commands/browser/saveState.mdx +++ b/docs/commands/browser/saveState.mdx @@ -88,3 +88,5 @@ it("test", async ({ browser }) => { ## Related Commands {#related} - [restoreState](../restoreState) +- [afterAll](../../../config/after-all) +- [beforeAll](../../../config/before-all) 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 index 27f3327..8915747 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx @@ -1,3 +1,5 @@ +import Admonition from "@theme/Admonition"; + # restoreState ## Обзор {#overview} @@ -98,6 +100,50 @@ it("test", async ({ browser }) => { }); ``` +Пример реализации аутентификации в тестах с использованием saveState/restoreState и хука beforeAll. + +```typescript +import { ConfigInput, WdioBrowser } from "testplane"; +import { launchBrowser } from "testplane/unstable"; + +export default { + gridUrl: "local", + beforeAll: async ({ config }) => { + const b = await launchBrowser(config.browsers["chrome"]!); + + await b.url("https://our-site.com"); + await b.$("input.login").setValue("user@example.com"); + await b.$("input.password").setValue("password123"); + + await b.saveState({ path: "./.testplane/state.json" }); + await b.deleteSession(); + }, + sets: { + /* ... */ + }, + browsers: { + chrome: { + headless: false, + desiredCapabilities: { + browserName: "chrome", + }, + }, + }, + plugins: { + /* ... */ + "@testplane/global-hook": { + enabled: true, + beforeEach: async ({ browser }: { browser: WdioBrowser }) => { + await browser.url("https://our-site.com"); + await browser.restoreState({ path: "./.testplane/state.json" }); + }, + }, + }, +} satisfies ConfigInput; +``` + ## Связанные команды {#related} - [saveState](../saveState) +- [afterAll](../../../config/after-all) +- [beforeAll](../../../config/before-all) 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 index a610821..cf468c2 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx @@ -86,3 +86,5 @@ it("test", async ({ browser }) => { ## Связанные команды {#related} - [restoreState](../restoreState) +- [afterAll](../../../config/after-all) +- [beforeAll](../../../config/before-all)