WebdriverIO assertion library inspired by expect
- Waits for expectations to succeed
- Supports single element
$()& multiple elements$$() - Detailed error messages
- Works in Mocha, Cucumber, Jest, and Jasmine
- Built-in types for TypeScript and JS autocompletion
npm install expect-webdriverio- Install your test framework adapter (if not already set up via WDIO testrunner):
- Mocha (default):
npm install @wdio/mocha-framework - Jasmine:
npm install @wdio/jasmine-framework - Cucumber:
npm install @wdio/cucumber-framework - Jest: No adapter needed — see Jest Framework section
- Mocha (default):
Note: WebdriverIO v9.0.0 or higher is required!
If you run your tests through the WDIO testrunner, no additional setup is needed. WebdriverIO initializes expect-webdriverio and makes expect available in the global scope so you can use it directly in your tests:
await expect($('button')).toBeDisplayed()
await expect($$('buttons')).toBeDisplayed()See more Examples.
- Local Runner: Fully compatible. You can leverage your test framework adapter as mentioned above.
- Browser Runner: Designed for component frameworks like React, Preact, Vue.js, Svelte, and SolidJS, with a few known limitations. For details, see the Browser Runner Framework section.
If you use WebdriverIO in standalone mode (without @wdio/globals), make sure you import expect-webdriverio before using it anywhere.
import { remote } from 'webdriverio'
import { expect } from 'expect-webdriverio'
;(async () => {
const browser = await remote({
capabilities: {
browserName: 'chrome'
}
})
await browser.url('https://webdriver.io')
const $button = await browser.$('button')
await expect($button).toBeDisplayed()
await browser.deleteSession()
})().catch(console.error)Please see the API documentation.
Error messages are informative out of the box and contain:
- Full element selector, like
$('form') - Actual and expected values
- Highlighted differences (text assertions)
First of all, feel free to raise an issue with your suggestions or help with PRs!
- Cookie matchers
- Multiremote support (in progress)

