Skip to content

Commit a21253e

Browse files
author
rocketraccoon
committed
feat(testplane): add afterAll/beforeAll docs
1 parent 5f69c27 commit a21253e

File tree

12 files changed

+248
-19
lines changed

12 files changed

+248
-19
lines changed

docs/command-line/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ testplane --repl --grep 'my test name' --browser chrome
192192
- `--keep-browser-on-fail` - the same as the `--keep-browser` option, but the browser will only remain open if the tests fail.
193193
194194
Example of console output with connection information to the browser:
195+
195196
```
196197
[15:44:38 +0700] Testplane run has finished, but the browser won't be closed, because you passed the --keep-browser argument.
197198
[15:44:38 +0700] You may attach to this browser using the following capabilities:

docs/commands/browser/restoreState.mdx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
Browser command that restores session state (cookies, local and session storages) from a file or variable.
66

77
<Admonition type="warning">
8-
If you are using the `webdriver` automation protocol, you have to provide `webSocketUrl: true` in `desiredCapabilities` in config browser settings.
9-
For the `devtools` protocol, you don't need additional settings.
8+
If you are using the `webdriver` automation protocol, you have to provide `webSocketUrl: true`
9+
in `desiredCapabilities` in config browser settings. For the `devtools` protocol, you don't need
10+
additional settings.
1011
</Admonition>
1112

1213
## Usage {#usage}
@@ -18,7 +19,7 @@ Data for restore state you can get from the [saveState](../saveState) command.
1819

1920
```typescript
2021
await browser.restoreState({
21-
path: './stateDump.json',
22+
path: "./stateDump.json",
2223
data: stateDump,
2324
cookies: true,
2425
localStorage: true,
@@ -40,17 +41,19 @@ await browser.restoreState({
4041
<tr><td>sessionStorage</td><td>Boolean</td><td>Enable restore sessionStorage (true by default).</td></tr>
4142

4243
</tbody>
44+
4345
</table>
4446

4547
## Usage Examples {#examples}
4648

4749
Restore state from file.
50+
4851
```typescript
4952
it("test", async ({ browser }) => {
5053
await browser.url("https://github.com/gemini-testing/testplane");
5154

5255
await browser.restoreState({
53-
path: './stateDump.json',
56+
path: "./stateDump.json",
5457
});
5558

5659
// Reload page for see auth result.

docs/commands/browser/saveState.mdx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import Admonition from "@theme/Admonition";
77
Browser command that saves session state (cookies, local and session storages).
88

99
<Admonition type="warning">
10-
If you are using the `webdriver` automation protocol, you have to provide `webSocketUrl: true` in `desiredCapabilities` in config browser settings.
11-
For the `devtools` protocol, you don't need additional settings.
10+
If you are using the `webdriver` automation protocol, you have to provide `webSocketUrl: true`
11+
in `desiredCapabilities` in config browser settings. For the `devtools` protocol, you don't need
12+
additional settings.
1213
</Admonition>
1314

1415
## Usage {#usage}
@@ -22,7 +23,7 @@ After saving the state, you can use it in the [restoreState](../restoreState) co
2223
import type { SaveStateData } from "testplane";
2324

2425
const stateDump: SaveStateData = await browser.saveState({
25-
path: './stateDump.json',
26+
path: "./stateDump.json",
2627
cookies: true,
2728
localStorage: true,
2829
sessionStorage: true,
@@ -42,17 +43,19 @@ const stateDump: SaveStateData = await browser.saveState({
4243
<tr><td>sessionStorage</td><td>Boolean</td><td>Enable save sessionStorage (true by default).</td></tr>
4344

4445
</tbody>
46+
4547
</table>
4648

4749
## Usage Examples {#examples}
4850

4951
Save state in file.
52+
5053
```typescript
5154
it("test", async ({ browser }) => {
5255
await browser.url("https://github.com/gemini-testing/testplane");
5356

5457
await browser.saveState({
55-
path: './stateDump.json',
58+
path: "./stateDump.json",
5659
});
5760
});
5861
```

docs/config/after-all.mdx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# afterAll
2+
3+
## Overview {#overview}
4+
5+
This parameter is a hook. The function specified for this parameter will be automatically called after tests are completed.
6+
7+
The context of the function is the Testplane config. Also function receive config in arguments.
8+
9+
## Usage Example {#example}
10+
11+
Here is an example of suing this hook for logout.
12+
13+
```typescript title="testplane.config.ts"
14+
import { launchBrowser } from "testplane/unstable";
15+
16+
export default {
17+
// ...
18+
browsers: {
19+
chrome: {
20+
headless: true,
21+
desiredCapabilities: {
22+
webSocketUrl: true,
23+
browserName: "chrome",
24+
},
25+
},
26+
firefox: {
27+
headless: true,
28+
desiredCapabilities: {
29+
webSocketUrl: true,
30+
browserName: "firefox",
31+
},
32+
},
33+
},
34+
afterAll: async () => {
35+
// launch a new browser with existing config
36+
const browser = await launchBrowser(this.config.browsers.chrome);
37+
38+
await browser.url("https://example.com");
39+
40+
// login using saved state
41+
await browser.restoreState({
42+
path: "./dump.json",
43+
});
44+
45+
// do logout things (press logout button etc.)
46+
47+
await browser.deleteSession();
48+
},
49+
};
50+
```
51+
52+
## Related {#related}
53+
54+
- [beforeAll](../before-all)

docs/config/before-all.mdx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# beforeAll
2+
3+
## Overview {#overview}
4+
5+
This parameter is a hook. The function specified for this parameter will be automatically called before tests running.
6+
7+
The context of the function is the Testplane config. Also function receive config in arguments.
8+
9+
## Usage Example {#example}
10+
11+
Here is an example of using this hook for logging in and getting session data for use in tests.
12+
13+
```typescript title="testplane.config.ts"
14+
import { launchBrowser } from "testplane/unstable";
15+
16+
export default {
17+
// ...
18+
browsers: {
19+
chrome: {
20+
headless: true,
21+
desiredCapabilities: {
22+
webSocketUrl: true,
23+
browserName: "chrome",
24+
},
25+
},
26+
firefox: {
27+
headless: true,
28+
desiredCapabilities: {
29+
webSocketUrl: true,
30+
browserName: "firefox",
31+
},
32+
},
33+
},
34+
beforeAll: async () => {
35+
// launch a new browser with existing config
36+
const browser = await launchBrowser(this.config.browsers.chrome);
37+
38+
await browser.url("https://example.com");
39+
40+
// do login things, type username/password etc.
41+
42+
// save dump with state (cookies, localStorage) for using in tests
43+
await browser.saveState({
44+
path: "./dump.json",
45+
});
46+
47+
await browser.deleteSession();
48+
},
49+
};
50+
```
51+
52+
## Related {#related}
53+
54+
- [afterAll](../after-all)

docs/reference/testplane-standalone-api.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { launchBrowser } from "testplane/unstable";
1818
// Launch a new browser with the given settings
1919
const browser = await launchBrowser({
2020
desiredCapabilities: {
21-
browserName: 'chrome',
21+
browserName: "chrome",
2222
},
2323
headless: false,
2424
});

i18n/ru/docusaurus-plugin-content-docs/current/command-line/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ testplane --repl --grep 'my test name' --browser chrome
193193
- `--keep-browser-on-fail` - то же, что и опция `--keep-browser`, только браузер останется только в том случае, если тесты завершатся неуспешно
194194
195195
Пример вывода в консоли c информацией для подключения к браузеру
196+
196197
```
197198
[15:44:38 +0700] Testplane run has finished, but the browser won't be closed, because you passed the --keep-browser argument.
198199
[15:44:38 +0700] You may attach to this browser using the following capabilities:

i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/restoreState.mdx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
Команда для восстановления данных (cookies, local and session storages) из файла или объекта.
66

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

1213
## Использование {#usage}
@@ -30,11 +31,12 @@
3031
<tr><td>sessionStorage</td><td>Boolean</td><td>Включить восстановление sessionStorage (true по умолчанию).</td></tr>
3132

3233
</tbody>
34+
3335
</table>
3436

3537
```typescript
3638
await browser.restoreState({
37-
path: './stateDump.json',
39+
path: "./stateDump.json",
3840
data: stateDump,
3941
cookies: true,
4042
localStorage: true,
@@ -45,12 +47,13 @@ await browser.restoreState({
4547
## Примеры использования {#examples}
4648

4749
Восстановление данных из файла.
50+
4851
```typescript
4952
it("test", async ({ browser }) => {
5053
await browser.url("https://github.com/gemini-testing/testplane");
5154

5255
await browser.restoreState({
53-
path: './stateDump.json',
56+
path: "./stateDump.json",
5457
});
5558

5659
// Reload page for see auth result.

i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/saveState.mdx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import Admonition from "@theme/Admonition";
77
Команда для сохранения состояния страницы (cookies, local и session storages).
88

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

1415
## Использование {#usage}
@@ -22,7 +23,7 @@ import Admonition from "@theme/Admonition";
2223
import type { SaveStateData } from "testplane";
2324

2425
const stateDump: SaveStateData = await browser.saveState({
25-
path: './stateDump.json',
26+
path: "./stateDump.json",
2627
cookies: true,
2728
localStorage: true,
2829
sessionStorage: true,
@@ -42,18 +43,19 @@ const stateDump: SaveStateData = await browser.saveState({
4243
<tr><td>sessionStorage</td><td>Boolean</td><td>Включить сохранение sessionStorage (true по умолчанию).</td></tr>
4344

4445
</tbody>
45-
</table>
4646

47+
</table>
4748

4849
## Примеры использования {#examples}
4950

5051
Сохранение данных в файл.
52+
5153
```typescript
5254
it("test", async ({ browser }) => {
5355
await browser.url("https://github.com/gemini-testing/testplane");
5456

5557
await browser.saveState({
56-
path: './stateDump.json',
58+
path: "./stateDump.json",
5759
});
5860
});
5961
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# afterAll
2+
3+
## Обзор {#overview}
4+
5+
Данный параметр является хуком. Функция, заданная для данного параметра, будет автоматически вызвана после прохождения тестов.
6+
7+
Контекстом функции является конфиг Testplane. Так же функция принимает конфиг в аргументе.
8+
9+
## Пример использования {#example}
10+
11+
Пример разлогина после выполнения тестов.
12+
13+
```typescript title="testplane.config.ts"
14+
import { launchBrowser } from "testplane/unstable";
15+
16+
export default {
17+
// ...
18+
browsers: {
19+
chrome: {
20+
headless: true,
21+
desiredCapabilities: {
22+
webSocketUrl: true,
23+
browserName: "chrome",
24+
},
25+
},
26+
firefox: {
27+
headless: true,
28+
desiredCapabilities: {
29+
webSocketUrl: true,
30+
browserName: "firefox",
31+
},
32+
},
33+
},
34+
afterAll: async () => {
35+
// launch a new browser with existing config
36+
const browser = await launchBrowser(this.config.browsers.chrome);
37+
38+
await browser.url("https://example.com");
39+
40+
// login using saved state
41+
await browser.restoreState({
42+
path: "./dump.json",
43+
});
44+
45+
// do logout things (press logout button etc.)
46+
47+
await browser.deleteSession();
48+
},
49+
};
50+
```
51+
52+
## Связанные хуки {#related}
53+
54+
- [beforeAll](../before-all)

0 commit comments

Comments
 (0)