Assertion
Note: This document is only valid for WebdriverIO > v6.x. If you run an older version of WebdriverIO, please install
expect-webdriverio
separately and set it up according to its documentation.
The WDIO testrunner comes with a built in assertion library that allows you to make powerful assertions on various aspects of the browser or elements within your (web) application. It extends Jests Matchers functionality with additional, for e2e testing optimized, matchers, e.g.:
const $button = $('button')
expect($button).toBeDisplayed()
const $button = await $('button')
await expect($button).toBeDisplayed()
or
const selectOptions = $$('form select>option')
// make sure there is at least one option in select
expect(selectOptions).toHaveChildren({ gte: 1 })
const selectOptions = await $$('form select>option')
// make sure there is at least one option in select
await expect(selectOptions).toHaveChildren({ gte: 1 })
For the full list, see the expect API doc.