-
Couldn't load subscription status.
- 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 5 commits
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,70 @@ | ||
| import Admonition from "@theme/Admonition"; | ||
|
|
||
| # restoreState | ||
|
|
||
| ## Overview {#overview} | ||
|
|
||
| Browser command that restores session state (cookies, local and session storages) from a file or variable. | ||
|
|
||
| <Admonition type="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. | ||
| </Admonition> | ||
|
|
||
| ## 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. | ||
|
||
|
|
||
| ```typescript | ||
| await browser.restoreState({ | ||
| path: "./stateDump.json", | ||
| data: stateDump, | ||
| cookies: true, | ||
| localStorage: true, | ||
| sessionStorage: true, | ||
| }); | ||
| ``` | ||
|
|
||
| ## Command Parameters {#parameters} | ||
|
|
||
| <table> | ||
| <thead> | ||
| <tr><td>**Name**</td><td>**Type**</td><td>**Description**</td></tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr><td>path</td><td>String</td><td>Path to file with state.</td></tr> | ||
|
||
| <tr><td>data</td><td>SaveStateData</td><td>Object with state.</td></tr> | ||
| <tr><td>cookies</td><td>Boolean</td><td>Enable restore cookies (true by default).</td></tr> | ||
| <tr><td>localStorage</td><td>Boolean</td><td>Enable restore localStorage (true by default).</td></tr> | ||
| <tr><td>sessionStorage</td><td>Boolean</td><td>Enable restore sessionStorage (true by default).</td></tr> | ||
| <tr><td>cookieFilter</td><td>(cookie: Cookie) => boolean</td><td>Function for filtering cookies, receiving cookie objects, and returning boolean.</td></tr> | ||
|
|
||
| </tbody> | ||
|
|
||
| </table> | ||
|
|
||
| ## 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", | ||
| cookieFilter: ({ domain }) => domain === ".example.com", | ||
| }); | ||
|
|
||
| // 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,67 @@ | ||
| import Admonition from "@theme/Admonition"; | ||
|
|
||
| # saveState | ||
|
|
||
| ## Overview {#overview} | ||
|
|
||
| Browser command that saves session state (cookies, local and session storages). | ||
|
|
||
| <Admonition type="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. | ||
| </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 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"; | ||
|
|
||
| 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, | ||
| }); | ||
| ``` | ||
|
|
||
| ## Command Parameters {#parameters} | ||
|
|
||
| <table> | ||
| <thead> | ||
| <tr><td>**Name**</td><td>**Type**</td><td>**Description**</td></tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr><td>path</td><td>String</td><td>Path to file where state will be saved.</td></tr> | ||
|
||
| <tr><td>cookies</td><td>Boolean</td><td>Enable save cookies (true by default).</td></tr> | ||
|
||
| <tr><td>localStorage</td><td>Boolean</td><td>Enable save localStorage (true by default).</td></tr> | ||
| <tr><td>sessionStorage</td><td>Boolean</td><td>Enable save sessionStorage (true by default).</td></tr> | ||
| <tr><td>cookieFilter</td><td>(cookie: Cookie) => boolean</td><td>Function for filtering cookies, receiving cookie objects, and returning boolean.</td></tr> | ||
|
|
||
| </tbody> | ||
|
|
||
| </table> | ||
|
|
||
| ## 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", | ||
| cookieFilter: ({ domain }) => domain === ".example.com", | ||
| }); | ||
| }); | ||
| ``` | ||
|
|
||
| ## 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. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
sonic16x marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
|
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,70 @@ | ||
| import Admonition from "@theme/Admonition"; | ||
|
|
||
| # 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). | ||
|
|
||
| ## Параметры команды {#parameters} | ||
|
|
||
| <table> | ||
| <thead> | ||
| <tr><td>**Имя**</td><td>**Тип**</td><td>**Описание**</td></tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr><td>path</td><td>String</td><td>Путь к файлу с данными.</td></tr> | ||
| <tr><td>data</td><td>SaveStateData</td><td>Объект с данными.</td></tr> | ||
| <tr><td>cookies</td><td>Boolean</td><td>Включить восстановление кук (true по умолчанию).</td></tr> | ||
| <tr><td>localStorage</td><td>Boolean</td><td>Включить восстановление localStorage (true по умолчанию).</td></tr> | ||
| <tr><td>sessionStorage</td><td>Boolean</td><td>Включить восстановление sessionStorage (true по умолчанию).</td></tr> | ||
| <tr><td>cookieFilter</td><td>(cookie: Cookie) => boolean</td><td>Функция для фильтрации кук, принимает объект куки и возвращает boolean.</td></tr> | ||
|
|
||
| </tbody> | ||
|
|
||
| </table> | ||
|
|
||
| ```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", | ||
| cookieFilter: ({ domain }) => domain === ".example.com", | ||
| }); | ||
|
|
||
| // Reload page for see auth result. | ||
| await browser.refresh(); | ||
| }); | ||
| ``` | ||
|
|
||
| ## Связанные команды {#related} | ||
|
|
||
| - [saveState](../saveState) | ||
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?