Skip to content

Latest commit

 

History

1,877 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

expect-webdriverio Test

WebdriverIO assertion library inspired by expect

Key Features

  • Waits for expectations to succeed
  • Supports single element $() & multiple elements $$()
  • Supports multi-remote browsers & elements, with one expected value per browser instance
  • Detailed error messages
  • Works in Mocha, Cucumber, Jest, and Jasmine
  • Built-in types for TypeScript and JS autocompletion

Installation

  1. npm install expect-webdriverio
  2. 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

Note: WebdriverIO v9.31.5 or higher is required!

Usage

Using WebdriverIO Testrunner

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.

Multi-remote

With multi-remote, assertions check every browser instance, with a single expected value or one per instance:

await expect(multiRemoteBrowser).toHaveTitle('WebdriverIO')
await expect(multiRemoteBrowser.$('h1')).toHaveText(expect.multiRemote({ chrome: 'Welcome', firefox: 'Bienvenue' }))

Some feature flags and WebdriverIO environment variables are required or recommended, see Multi-remote Support.

Local & Browser Runners

  • 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.

Using in Standalone Mode

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)

API

Please see the API documentation.

Error Messages

Error messages are informative out of the box and contain:

  • Full element selector, like $('form')
  • Actual and expected values
  • Highlighted differences (text assertions)

toHaveText toHaveElementClass

What's Next?

First of all, feel free to raise an issue with your suggestions or help with PRs!

Planned

  • Cookie matchers
  • Multi-remote support for number, size and object matchers (in progress)

About

WebdriverIO Assertion Library

Topics

Resources

Code of conduct

Security policy

Stars

86 stars

Watchers

8 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages