Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1,812 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

expect-webdriverio Test

WebdriverIO Assertion library inspired by expect

Key Features

  • Waits for expectation to succeed
  • Support single element & multi-elements
  • Detailed error messages
  • Works in Mocha, Cucumber, Jest, Jasmine
  • Builtin 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.0.0 or higher is required!

Usage

Using WebdriverIO Testrunner

If you run your tests through the WDIO testrunner no additional setup is needed. WebdriverIO initialises expect-webdriverio and makes expect available in the global scope. So you can use it directly in your tests:

const button = await $('button')
await expect(button).toBeDisplayed()

See more Examples

Using in a standalone script

If you embed WebdriverIO in a standalone (without @wdio/globals), make sure you import expect-webdriverio before you use 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 API doc

Error messages

Error messages are informative out of the box and contain:

  • full element selector, like $('form').$('input')
  • actual and expected values
  • highlight the difference (texts assertions)

toHaveText toHaveElementClass

What's next?

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

Planned

  • cookie
  • multiremote support (coming)

Releases

Sponsor this project

Packages

Used by

Contributors

Languages