Skip to content
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

fix(commands): fix addCommand and overwriteCommand examples #44

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
49 changes: 32 additions & 17 deletions docs/commands/browser/addCommand.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,46 @@ Use the `addCommand` command to add your own command to the browser or to an ele
## Usage {#usage}

```javascript
await browser.addCommand(name, callback, elementScope);
browser.addCommand(name, callback, elementScope);
```

## Command Parameters {#parameters}

<table>
<thead>
<tr><td>**Name**</td><td>**Type**</td><td>**Description**</td></tr>
</thead>
<tbody>
<tr><td>name</td><td>String</td><td>Custom command name.</td></tr>
<tr><td>callback</td><td>Function</td><td>Command implementation function.</td></tr>
<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>

</tbody>
<thead>
<tr>
<td>**Name**</td>
<td>**Type**</td>
<td>**Description**</td>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td>Custom command name.</td>
</tr>
<tr>
<td>callback</td>
<td>Function</td>
<td>Command implementation function.</td>
</tr>
<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>
</tbody>
</table>

## Usage Examples {#examples}

```javascript
// add the getUrlAndTitle command
await browser.addCommand("getUrlAndTitle", async function (customParam) {
browser.addCommand("getUrlAndTitle", async function (customParam) {
return {
url: await this.getUrl(), // `this` here and below refers to the "browser" object
title: await this.getTitle(),
Expand All @@ -45,15 +63,12 @@ await browser.addCommand("getUrlAndTitle", async function (customParam) {

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

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

assert.strictEqual(result.url, "https://webdriver.io");
assert.strictEqual(
result.title,
"WebdriverIO · Next-gen browser and mobile automation test framework for Node.js",
);
assert.strictEqual(result.url, "https://testplane.io");
assert.strictEqual(result.title, "Testplane Docs | Testplane Docs");
assert.strictEqual(result.customParam, "foobar");
});
```
Expand Down
39 changes: 28 additions & 11 deletions docs/commands/browser/overwriteCommand.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,42 @@ await browser.overwriteCommand(name, callback, elementScope);
## Command Parameters {#parameters}

<table>
<thead>
<tr><td>**Name**</td><td>**Type**</td><td>**Description**</td></tr>
</thead>
<tbody>
<tr><td>name</td><td>String</td><td>The name of the custom command.</td></tr>
<tr><td>callback</td><td>Function</td><td>The function implementation of the command.</td></tr>
<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>

</tbody>
<thead>
<tr>
<td>**Name**</td>
<td>**Type**</td>
<td>**Description**</td>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td>The name of the custom command.</td>
</tr>
<tr>
<td>callback</td>
<td>Function</td>
<td>The function implementation of the command.</td>
</tr>
<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>

</tbody>

</table>

## Usage Examples {#examples}

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

origPauseFunction(ms);
await origPauseFunction(ms);

return ms;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,46 @@ import Admonition from "@theme/Admonition";
## Использование {#usage}

```javascript
await browser.addCommand(name, callback, elementScope);
browser.addCommand(name, callback, elementScope);
```

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

<table>
<thead>
<tr><td>**Имя**</td><td>**Тип**</td><td>**Описание**</td></tr>
</thead>
<tbody>
<tr><td>name</td><td>String</td><td>Имя кастомной команды.</td></tr>
<tr><td>callback</td><td>Function</td><td>Функция-реализация команды.</td></tr>
<tr><td>elementScope</td><td>Boolean</td><td>Если значение _true_, то добавить команду к элементу, а не к браузеру. По умолчанию: _false_.</td></tr>

</tbody>
<thead>
<tr>
<td>**Имя**</td>
<td>**Тип**</td>
<td>**Описание**</td>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td>Имя кастомной команды.</td>
</tr>
<tr>
<td>callback</td>
<td>Function</td>
<td>Функция-реализация команды.</td>
</tr>
<tr>
<td>elementScope</td>
<td>Boolean</td>
<td>
Если значение _true_, то добавить команду к элементу, а не к браузеру. По умолчанию:
_false_.
</td>
</tr>
</tbody>
</table>

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

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

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

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

assert.strictEqual(result.url, "https://webdriver.io");
assert.strictEqual(
result.title,
"WebdriverIO · Next-gen browser and mobile automation test framework for Node.js",
);
assert.strictEqual(result.url, "https://testplane.io");
assert.strictEqual(result.title, "Testplane Docs | Testplane Docs");
assert.strictEqual(result.customParam, "foobar");
});
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,43 @@ await browser.overwriteCommand(name, callback, elementScope);
## Параметры команды {#parameters}

<table>
<thead>
<tr><td>**Имя**</td><td>**Тип**</td><td>**Описание**</td></tr>
</thead>
<tbody>
<tr><td>name</td><td>String</td><td>Имя кастомной команды.</td></tr>
<tr><td>callback</td><td>Function</td><td>Функция-реализация команды.</td></tr>
<tr><td>elementScope</td><td>Boolean</td><td>Если значение _true_, то добавить команду к элементу, а не к браузеру. По умолчанию: _false_.</td></tr>

</tbody>
<thead>
<tr>
<td>**Имя**</td>
<td>**Тип**</td>
<td>**Описание**</td>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td>String</td>
<td>Имя кастомной команды.</td>
</tr>
<tr>
<td>callback</td>
<td>Function</td>
<td>Функция-реализация команды.</td>
</tr>
<tr>
<td>elementScope</td>
<td>Boolean</td>
<td>
Если значение _true_, то добавить команду к элементу, а не к браузеру. По умолчанию:
_false_.
</td>
</tr>
</tbody>
</table>

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

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

origPauseFunction(ms);
await origPauseFunction(ms);

return ms;
});
Expand Down
Loading