https://github.com/webdriverio/expect-webdriverio
WebdriverIO Assertion Library
https://github.com/webdriverio/expect-webdriverio
assertion-library expect hacktoberfest webdriverio
Last synced: 5 months ago
JSON representation
WebdriverIO Assertion Library
- Host: GitHub
- URL: https://github.com/webdriverio/expect-webdriverio
- Owner: webdriverio
- License: mit
- Created: 2019-11-21T14:09:38.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-05-18T01:11:02.000Z (about 2 years ago)
- Last Synced: 2024-05-19T16:15:18.281Z (about 2 years ago)
- Topics: assertion-library, expect, hacktoberfest, webdriverio
- Language: TypeScript
- Homepage: https://webdriver.io
- Size: 6.73 MB
- Stars: 70
- Watchers: 13
- Forks: 48
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# expect-webdriverio [](https://github.com/webdriverio/expect-webdriverio/actions/workflows/test.yml)
###### [API](docs/API.md) | [TypeScript / JS Autocomplete](docs/Types.md) | [Examples](docs/Examples.md) | [Extending Matchers](docs/CustomMatchers.md)
> [WebdriverIO](https://webdriver.io/) Assertion library inspired by [expect](https://www.npmjs.com/package/expect)
## Key Features
- [waits](#default-options) for expectation to succeed
- detailed [error messages](#error-messages)
- works in Mocha, Cucumber, Jest, Jasmine
- builtin [types](docs/Types.md) 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](https://github.com/webdriverio/webdriverio) `v9.0.0` or higher is required!
## Usage
### Using WebdriverIO Testrunner
If you run your tests through the [WDIO testrunner](https://webdriver.io/docs/clioptions) 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:
```js
const $button = await $('button')
await expect($button).toBeDisplayed()
```
See more [Examples](docs/Examples.md)
### Using in a standalone script
If you embed WebdriverIO in a standalone script, make sure you import `expect-webdriverio` before you use it anywhere.
```js
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](docs/API.md)
## 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)


## 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)