项目作者: webdriverio

项目描述 :
WebdriverIO Assertion Library
高级语言: TypeScript
项目地址: git://github.com/webdriverio/expect-webdriverio.git
创建时间: 2019-11-21T14:09:38Z
项目社区:https://github.com/webdriverio/expect-webdriverio

开源协议:MIT License

下载


expect-webdriverio Test

API | TypeScript / JS Autocomplete | Examples | Extending Matchers

WebdriverIO Assertion library inspired by expect

Key Features

  • waits for expectation to succeed
  • detailed error messages
  • works in Mocha, Cucumber, Jest, Jasmine
  • builtin types for TypeScript and JS autocompletion

Installation

  1. npm install expect (Jasmine and Jest users should skip this step)
  2. npm install expect-webdriverio

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:

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

See more Examples

Using in a standalone script

If you embed WebdriverIO in a standalone script, make sure you import expect-webdriverio before you use it anywhere.

  1. import { remote } from 'webdriverio'
  2. import { expect } from 'expect-webdriverio'
  3. ;(async () => {
  4. const browser = await remote({
  5. capabilities: {
  6. browserName: 'chrome'
  7. }
  8. })
  9. await browser.url('https://webdriver.io')
  10. const $button = await browser.$('button')
  11. await expect($button).toBeDisplayed()
  12. await browser.deleteSession()
  13. })().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

  • css matcher
  • size matcher
  • cookie / localStorage matchers?
  • text regex matchers
  • multiremote support (if requested)