From ab4b861572d702a47686749b9e0249bd75fa07af Mon Sep 17 00:00:00 2001 From: sipayrt <sipayrt@yandex.ru> Date: Thu, 7 Nov 2024 11:26:12 +0300 Subject: [PATCH] fix(commands): fix addCommand and overwriteCommand examples --- docs/commands/browser/addCommand.mdx | 49 ++++++++++++------- docs/commands/browser/overwriteCommand.mdx | 39 ++++++++++----- .../current/commands/browser/addCommand.mdx | 49 ++++++++++++------- .../commands/browser/overwriteCommand.mdx | 40 ++++++++++----- 4 files changed, 121 insertions(+), 56 deletions(-) diff --git a/docs/commands/browser/addCommand.mdx b/docs/commands/browser/addCommand.mdx index 3e69e17..be16c61 100644 --- a/docs/commands/browser/addCommand.mdx +++ b/docs/commands/browser/addCommand.mdx @@ -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(), @@ -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"); }); ``` diff --git a/docs/commands/browser/overwriteCommand.mdx b/docs/commands/browser/overwriteCommand.mdx index 4ee162f..3872381 100644 --- a/docs/commands/browser/overwriteCommand.mdx +++ b/docs/commands/browser/overwriteCommand.mdx @@ -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; }); diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/addCommand.mdx b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/addCommand.mdx index cf181f8..f856cdf 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/addCommand.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/addCommand.mdx @@ -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(), @@ -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"); }); ``` diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/overwriteCommand.mdx b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/overwriteCommand.mdx index ac94f46..027754e 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/overwriteCommand.mdx +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/browser/overwriteCommand.mdx @@ -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; });