Skip to content

Commit ab4b861

Browse files
committed
fix(commands): fix addCommand and overwriteCommand examples
1 parent d012d1d commit ab4b861

File tree

4 files changed

+121
-56
lines changed

4 files changed

+121
-56
lines changed

docs/commands/browser/addCommand.mdx

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,46 @@ Use the `addCommand` command to add your own command to the browser or to an ele
1414
## Usage {#usage}
1515

1616
```javascript
17-
await browser.addCommand(name, callback, elementScope);
17+
browser.addCommand(name, callback, elementScope);
1818
```
1919

2020
## Command Parameters {#parameters}
2121

2222
<table>
23-
<thead>
24-
<tr><td>**Name**</td><td>**Type**</td><td>**Description**</td></tr>
25-
</thead>
26-
<tbody>
27-
<tr><td>name</td><td>String</td><td>Custom command name.</td></tr>
28-
<tr><td>callback</td><td>Function</td><td>Command implementation function.</td></tr>
29-
<tr><td>elementScope</td><td>Boolean</td><td>If the value is _true_, add the command to the element instead of the browser. Default: _false_.</td></tr>
30-
31-
</tbody>
23+
<thead>
24+
<tr>
25+
<td>**Name**</td>
26+
<td>**Type**</td>
27+
<td>**Description**</td>
28+
</tr>
29+
</thead>
30+
<tbody>
31+
<tr>
32+
<td>name</td>
33+
<td>String</td>
34+
<td>Custom command name.</td>
35+
</tr>
36+
<tr>
37+
<td>callback</td>
38+
<td>Function</td>
39+
<td>Command implementation function.</td>
40+
</tr>
41+
<tr>
42+
<td>elementScope</td>
43+
<td>Boolean</td>
44+
<td>
45+
If the value is _true_, add the command to the element instead of the browser.
46+
Default: _false_.
47+
</td>
48+
</tr>
49+
</tbody>
3250
</table>
3351

3452
## Usage Examples {#examples}
3553

3654
```javascript
3755
// add the getUrlAndTitle command
38-
await browser.addCommand("getUrlAndTitle", async function (customParam) {
56+
browser.addCommand("getUrlAndTitle", async function (customParam) {
3957
return {
4058
url: await this.getUrl(), // `this` here and below refers to the "browser" object
4159
title: await this.getTitle(),
@@ -45,15 +63,12 @@ await browser.addCommand("getUrlAndTitle", async function (customParam) {
4563

4664
// use the new getUrlAndTitle command
4765
it("should use my add command", async ({ browser }) => {
48-
await browser.url("https://webdriver.io");
66+
await browser.url("https://testplane.io");
4967

5068
const result = await browser.getUrlAndTitle("foobar");
5169

52-
assert.strictEqual(result.url, "https://webdriver.io");
53-
assert.strictEqual(
54-
result.title,
55-
"WebdriverIO · Next-gen browser and mobile automation test framework for Node.js",
56-
);
70+
assert.strictEqual(result.url, "https://testplane.io");
71+
assert.strictEqual(result.title, "Testplane Docs | Testplane Docs");
5772
assert.strictEqual(result.customParam, "foobar");
5873
});
5974
```

docs/commands/browser/overwriteCommand.mdx

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,42 @@ await browser.overwriteCommand(name, callback, elementScope);
1919
## Command Parameters {#parameters}
2020

2121
<table>
22-
<thead>
23-
<tr><td>**Name**</td><td>**Type**</td><td>**Description**</td></tr>
24-
</thead>
25-
<tbody>
26-
<tr><td>name</td><td>String</td><td>The name of the custom command.</td></tr>
27-
<tr><td>callback</td><td>Function</td><td>The function implementation of the command.</td></tr>
28-
<tr><td>elementScope</td><td>Boolean</td><td>If the value is _true_, add the command to the element instead of the browser. Default: _false_.</td></tr>
29-
30-
</tbody>
22+
<thead>
23+
<tr>
24+
<td>**Name**</td>
25+
<td>**Type**</td>
26+
<td>**Description**</td>
27+
</tr>
28+
</thead>
29+
<tbody>
30+
<tr>
31+
<td>name</td>
32+
<td>String</td>
33+
<td>The name of the custom command.</td>
34+
</tr>
35+
<tr>
36+
<td>callback</td>
37+
<td>Function</td>
38+
<td>The function implementation of the command.</td>
39+
</tr>
40+
<tr>
41+
<td>elementScope</td>
42+
<td>Boolean</td>
43+
<td>If the value is _true_, add the command to the element instead of the browser. Default: _false_.</td>
44+
</tr>
45+
46+
</tbody>
47+
3148
</table>
3249

3350
## Usage Examples {#examples}
3451

3552
```javascript
3653
// log the pause duration in ms before the pause and then return the value
37-
await browser.overwriteCommand("pause", function (origPauseFunction, ms) {
54+
await browser.overwriteCommand("pause", async function (origPauseFunction, ms) {
3855
console.log(`Sleeping for ${ms}`);
3956

40-
origPauseFunction(ms);
57+
await origPauseFunction(ms);
4158

4259
return ms;
4360
});

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

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,46 @@ import Admonition from "@theme/Admonition";
1414
## Использование {#usage}
1515

1616
```javascript
17-
await browser.addCommand(name, callback, elementScope);
17+
browser.addCommand(name, callback, elementScope);
1818
```
1919

2020
## Параметры команды {#parameters}
2121

2222
<table>
23-
<thead>
24-
<tr><td>**Имя**</td><td>**Тип**</td><td>**Описание**</td></tr>
25-
</thead>
26-
<tbody>
27-
<tr><td>name</td><td>String</td><td>Имя кастомной команды.</td></tr>
28-
<tr><td>callback</td><td>Function</td><td>Функция-реализация команды.</td></tr>
29-
<tr><td>elementScope</td><td>Boolean</td><td>Если значение _true_, то добавить команду к элементу, а не к браузеру. По умолчанию: _false_.</td></tr>
30-
31-
</tbody>
23+
<thead>
24+
<tr>
25+
<td>**Имя**</td>
26+
<td>**Тип**</td>
27+
<td>**Описание**</td>
28+
</tr>
29+
</thead>
30+
<tbody>
31+
<tr>
32+
<td>name</td>
33+
<td>String</td>
34+
<td>Имя кастомной команды.</td>
35+
</tr>
36+
<tr>
37+
<td>callback</td>
38+
<td>Function</td>
39+
<td>Функция-реализация команды.</td>
40+
</tr>
41+
<tr>
42+
<td>elementScope</td>
43+
<td>Boolean</td>
44+
<td>
45+
Если значение _true_, то добавить команду к элементу, а не к браузеру. По умолчанию:
46+
_false_.
47+
</td>
48+
</tr>
49+
</tbody>
3250
</table>
3351

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

3654
```javascript
3755
// добавляем команду getUrlAndTitle
38-
await browser.addCommand("getUrlAndTitle", async function (customParam) {
56+
browser.addCommand("getUrlAndTitle", async function (customParam) {
3957
return {
4058
url: await this.getUrl(), // `this` здесь и ниже относится к объекту "browser"
4159
title: await this.getTitle(),
@@ -45,15 +63,12 @@ await browser.addCommand("getUrlAndTitle", async function (customParam) {
4563

4664
// используем новую команду getUrlAndTitle
4765
it("should use my add command", async ({ browser }) => {
48-
await browser.url("https://webdriver.io");
66+
await browser.url("https://testplane.io");
4967

5068
const result = await browser.getUrlAndTitle("foobar");
5169

52-
assert.strictEqual(result.url, "https://webdriver.io");
53-
assert.strictEqual(
54-
result.title,
55-
"WebdriverIO · Next-gen browser and mobile automation test framework for Node.js",
56-
);
70+
assert.strictEqual(result.url, "https://testplane.io");
71+
assert.strictEqual(result.title, "Testplane Docs | Testplane Docs");
5772
assert.strictEqual(result.customParam, "foobar");
5873
});
5974
```

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,43 @@ await browser.overwriteCommand(name, callback, elementScope);
1919
## Параметры команды {#parameters}
2020

2121
<table>
22-
<thead>
23-
<tr><td>**Имя**</td><td>**Тип**</td><td>**Описание**</td></tr>
24-
</thead>
25-
<tbody>
26-
<tr><td>name</td><td>String</td><td>Имя кастомной команды.</td></tr>
27-
<tr><td>callback</td><td>Function</td><td>Функция-реализация команды.</td></tr>
28-
<tr><td>elementScope</td><td>Boolean</td><td>Если значение _true_, то добавить команду к элементу, а не к браузеру. По умолчанию: _false_.</td></tr>
29-
30-
</tbody>
22+
<thead>
23+
<tr>
24+
<td>**Имя**</td>
25+
<td>**Тип**</td>
26+
<td>**Описание**</td>
27+
</tr>
28+
</thead>
29+
<tbody>
30+
<tr>
31+
<td>name</td>
32+
<td>String</td>
33+
<td>Имя кастомной команды.</td>
34+
</tr>
35+
<tr>
36+
<td>callback</td>
37+
<td>Function</td>
38+
<td>Функция-реализация команды.</td>
39+
</tr>
40+
<tr>
41+
<td>elementScope</td>
42+
<td>Boolean</td>
43+
<td>
44+
Если значение _true_, то добавить команду к элементу, а не к браузеру. По умолчанию:
45+
_false_.
46+
</td>
47+
</tr>
48+
</tbody>
3149
</table>
3250

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

3553
```javascript
3654
// вывести время паузы в мс перед самой паузой и вернуть потом это значение
37-
await browser.overwriteCommand("pause", function (origPauseFunction, ms) {
55+
await browser.overwriteCommand("pause", async function (origPauseFunction, ms) {
3856
console.log(`Sleeping for ${ms}`);
3957

40-
origPauseFunction(ms);
58+
await origPauseFunction(ms);
4159

4260
return ms;
4361
});

0 commit comments

Comments
 (0)