Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions docs/commands/browser/restoreState.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# restoreState

## Overview {#overview}

Browser command that restore session state (cookies, local and session storages) from file or variable.

<Admonition type="warning">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this warning still needed?

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.
</Admonition>

## 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 }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use example from below here as well. Not necessarily replacing yours, you can just add it as a second one.

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)
47 changes: 47 additions & 0 deletions docs/commands/browser/saveState.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Admonition from "@theme/Admonition";

# saveState

## Overview {#overview}

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

<Admonition type="warning">
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.
</Admonition>

## Usage {#usage}

Command return state dump from page, it will include cookie, localStorage and sessionStorage.
Copy link
Member

@shadowusr shadowusr Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command returns

It will include cookies

etc. I think it would be good to let some LLM scan this for typos and improve wording

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any changes in this sentence, it still has mistakes, isn't it?

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({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be really nice to briefly comment what's exactly inside that SaveStateData object. Or, if the SaveStateData interface is simple enough, we can include it right in the example.

path: './stateDump.json',
cookies: true,
localStorage: true,
sessionStorage: true,
});
```

## Usage Examples {#examples}

Save state in file
```typescript
it("test", async ({ browser }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a more comprehensive example would bring much more value. Here's what I needed to do to setup simple save/restore workflow:

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('[email protected]');
        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;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

await browser.url("https://github.com/gemini-testing/testplane");

await browser.saveState({
path: './stateDump.json',
});
});
```

## Related Commands {#related}

- [restoreState](../restoreState)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add references to the new hooks as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All comments from english versions of these articles apply to ru localization as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# restoreState

## Обзор {#overview}

Команда для восстановления данных (cookies, local and session storages) из файла или объекта.

<Admonition type="warning">
Если вы используете `webdriver` automation protocol вы должны установить `webSocketUrl: true` в `desiredCapabilities` для браузера в конфиге.
Для `devtools` protocol не нужно дополнительных настроек.
</Admonition>

## Использование {#usage}

Вы можете восстановить данные из файла (используя параметр `path`) или из объекта (используя параметр`data`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of typos here e.g. "нуд=жные" and I'd use more structured language here. Again, I'd just use LLM to improve spelling and wording here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Но если вы укажете оба параметра то данные восстановятся из файла.
Так же вы можете указать параметры `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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Admonition from "@theme/Admonition";

# saveState

## Обзор {#overview}

Команда для сохранения состояния страницы (cookies, local и session storages).

<Admonition type="warning">
Если вы используете `webdriver` automation protocol вы должны установить `webSocketUrl: true` в `desiredCapabilities` для браузера в конфиге.
Для `devtools` protocol не нужно дополнительных настроек.
</Admonition>

## Использование {#usage}

Команда вернёт объект включающий cookie, localStorage и sessionStorage.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to have "Command Parameters" table like we do on other pages, e.g. https://testplane.io/docs/v8/commands/browser/setMeta/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Используя параметры вы можете выключить сохранение отдельных данных.
Так же вы можете указать параметр `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)
Loading