Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(docs): add docs for visual matchers #1409

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,119 @@ await expect(browser).toHaveUrl(/webdriver\.io/)
await expect(elem).toHaveElementClass(/Container/i)
```

## Visual Matchers

<!--
These matchers aren't implemented in the `expect-webdriverio` project and can be found
here: https://github.com/webdriverio-community/visual-testing/blob/e10f7005c1533f5b06811888a9cbb9020e6e765e/packages/service/src/matcher.ts
-->

The following matcher are implemented as part of the `@wdio/visual-service` plugin and only available when the service is set up. Make sure you follow the [set-up instructions](/docs/visual-testing) accordingly.

### toMatchElementSnapshot

Checks that if given element matches with snapshot of baseline.

##### Usage

```js
await expect($('.hero__title-logo')).toMatchElementSnapshot('wdioLogo', 0, {
// options
})
```

The expected result is by default `0`, so you can write the same assertion as:

```js
await expect($('.hero__title-logo')).toMatchElementSnapshot('wdioLogo', {
// options
})
```

or not pass in any options at all:

```js
await expect($('.hero__title-logo')).toMatchElementSnapshot()
```

### toMatchScreenSnapshot

Checks that if current screen matches with snapshot of baseline.

##### Usage

```js
await expect(browser).toMatchScreenSnapshot('partialPage', 0, {
// options
})
```

The expected result is by default `0`, so you can write the same assertion as:

```js
await expect(browser).toMatchScreenSnapshot('partialPage', {
// options
})
```

or not pass in any options at all:

```js
await expect(browser).toMatchScreenSnapshot('partialPage')
```

### toMatchFullPageSnapshot

Checks that if the full page screenshot matches with snapshot of baseline.

##### Usage

```js
await expect(browser).toMatchFullPageSnapshot('fullPage', 0, {
// options
})
```

The expected result is by default `0`, so you can write the same assertion as:

```js
await expect(browser).toMatchFullPageSnapshot('fullPage', {
// options
})
```

or not pass in any options at all:

```js
await expect(browser).toMatchFullPageSnapshot('fullPage')
```

### toMatchTabbablePageSnapshot

Checks that if the full page screenshot including tab marks matches with snapshot of baseline.

##### Usage

```js
await expect(browser).toMatchTabbablePageSnapshot('tabbable', 0, {
// options
})
```

The expected result is by default `0`, so you can write the same assertion as:

```js
await expect(browser).toMatchTabbablePageSnapshot('tabbable', {
// options
})
```

or not pass in any options at all:

```js
await expect(browser).toMatchTabbablePageSnapshot('tabbable')
```

## Default Matchers

In addition to the `expect-webdriverio` matchers you can use builtin Jest's [expect](https://jestjs.io/docs/en/expect) assertions or [expect/expectAsync](https://jasmine.github.io/api/3.5/global.html#expect) for Jasmine.
Expand Down
Loading