Skip to content

Commit

Permalink
Merge pull request #44 from gemini-testing/sp.fixOverwriteCommandExam…
Browse files Browse the repository at this point in the history
…ples

fix(commands): fix addCommand and overwriteCommand examples
  • Loading branch information
sipayRT authored Nov 7, 2024
2 parents d012d1d + ab4b861 commit 25030a5
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 56 deletions.
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

0 comments on commit 25030a5

Please sign in to comment.