From d202e7d9bec8330be405c7f6271328b685e25b57 Mon Sep 17 00:00:00 2001 From: sipayrt Date: Thu, 9 Jan 2025 18:32:58 +0300 Subject: [PATCH] docs: add info about expect timeout configuration --- docs/commands/expect/overview.mdx | 48 +++++++++++++++++++ .../_partials/examples/_system-example.mdx | 4 ++ .../current/commands/expect/overview.mdx | 48 +++++++++++++++++++ sidebars.ts | 24 +++++++++- 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 docs/commands/expect/overview.mdx create mode 100644 i18n/ru/docusaurus-plugin-content-docs/current/commands/expect/overview.mdx diff --git a/docs/commands/expect/overview.mdx b/docs/commands/expect/overview.mdx new file mode 100644 index 0000000..4243866 --- /dev/null +++ b/docs/commands/expect/overview.mdx @@ -0,0 +1,48 @@ +--- +sidebar_class_name: hidden +--- + +# Assertion with Expect + +## Overview + +When writing tests, it's often necessary to ensure that values meet certain criteria. With the `expect` function you have access to a variety of matchers that help verify different characteristics of the browser, element, or object mock. + +For example, you can check if the browser is on a specific page + +```typescript +await browser.url("https://webdriver.io/"); +// ... +await expect(browser).toHaveUrl("https://webdriver.io"); +``` + +or check if the element has an attribute with the specified value + +```typescript +const myInput = await browser.$("input"); +await expect(myInput).toHaveAttribute("class", "form-control"); +``` + +or check if the specified request has been made for your mock + +```typescript +const mock = browser.mock("**/api/todo*"); +// ... +await expect(mock).toBeRequested(); +``` + +By default, the timeout for executing asserts is 2000ms with a check interval of 100ms. However, if necessary, these values can be redefined in the [system section][system_config] in the general config. + +```typescript +{ +// another testplane configs + system: { + expectOpts: { + wait: 5000, + interval: 200, + } + } +} +``` + +[system_config]: ../../../config/system#expect_opts diff --git a/docs/config/_partials/examples/_system-example.mdx b/docs/config/_partials/examples/_system-example.mdx index 3fdfeb7..4067947 100644 --- a/docs/config/_partials/examples/_system-example.mdx +++ b/docs/config/_partials/examples/_system-example.mdx @@ -8,6 +8,10 @@ export default { mochaOpts: { timeout: 60000, }, + expectOpts: { + wait: 3000, + interval: 100, + }, ctx: { /* ... */ }, diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/commands/expect/overview.mdx b/i18n/ru/docusaurus-plugin-content-docs/current/commands/expect/overview.mdx new file mode 100644 index 0000000..5bcbfba --- /dev/null +++ b/i18n/ru/docusaurus-plugin-content-docs/current/commands/expect/overview.mdx @@ -0,0 +1,48 @@ +--- +sidebar_class_name: hidden +--- + +# Ассерты с помощью Expect + +## Обзор + +В ходе написания тестов нужно часто удостовериться, что значения отвечают определённым требованиям. С помощью функции expect у вас есть доступ к множеству «матчеров», которые помогают проверить различные характеристики браузера, элемента или мока объекта. + +Например, можно проверить находится ли браузер на заданной странице + +```typescript +await browser.url("https://webdriver.io/"); +// ... +await expect(browser).toHaveUrl("https://webdriver.io"); +``` + +или проверить есть ли у элемента атрибут с заданным значением + +```typescript +const myInput = await browser.$("input"); +await expect(myInput).toHaveAttribute("class", "form-control"); +``` + +или проверить был ли сделан указанный запрос для вашего мока + +```typescript +const mock = browser.mock("**/api/todo*"); +// ... +await expect(mock).toBeRequested(); +``` + +По умолчанию таймаут на выполнение ассертов равен 2000мс с интервалом проверок в 100мс. Но при необходимости эти значения можно переопределить в [секции system][system_config] в общем конфиге. + +```typescript +{ +// другие настройки testplane + system: { + expectOpts: { + wait: 5000, + interval: 200, + } + } +} +``` + +[system_config]: ../../../config/system#expect_opts diff --git a/sidebars.ts b/sidebars.ts index 9025fec..563d322 100644 --- a/sidebars.ts +++ b/sidebars.ts @@ -16,7 +16,29 @@ const sidebars: SidebarsConfig = { { type: "category", label: "Commands", - items: [{ type: "autogenerated", dirName: "commands" }], + items: [ + { + type: "category", + label: "browser", + items: [{ type: "autogenerated", dirName: "commands/browser" }], + }, + { + type: "category", + label: "element", + items: [{ type: "autogenerated", dirName: "commands/element" }], + }, + { + type: "category", + label: "expect", + items: [{ type: "autogenerated", dirName: "commands/expect" }], + link: { type: "doc", id: "commands/expect/overview" }, + }, + { + type: "category", + label: "mock", + items: [{ type: "autogenerated", dirName: "commands/mock" }], + }, + ], link: { type: "doc", id: "commands/overview" }, }, {