Skip to content
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
48 changes: 48 additions & 0 deletions docs/commands/expect/overview.mdx
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions docs/config/_partials/examples/_system-example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export default {
mochaOpts: {
timeout: 60000,
},
expectOpts: {
wait: 3000,
interval: 100,
},
ctx: {
/* ... */
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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
24 changes: 23 additions & 1 deletion sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
},
{
Expand Down
Loading