-
Notifications
You must be signed in to change notification settings - Fork 3
Docs for saveState and restoreState #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
7e531b0
5f69c27
a21253e
ba553af
c18d65e
7e48133
fc1ed2b
ca3ba6a
92087ad
8f38f3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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"> | ||
| 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 }) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| 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. | ||
|
||
| 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({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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;There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add references to the new hooks as well. |
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`) | ||
|
||
| Но если вы укажете оба параметра то данные восстановятся из файла. | ||
| Так же вы можете указать параметры `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. | ||
|
||
| Используя параметры вы можете выключить сохранение отдельных данных. | ||
| Так же вы можете указать параметр `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) | ||
There was a problem hiding this comment.
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?