playwright/docs/src/test-snapshots.md

29 lines
1.1 KiB
Markdown
Raw Normal View History

2021-05-27 20:30:03 -07:00
---
id: test-snapshots
title: "Snapshots"
---
Playwright Test includes the ability to produce and compare snapshots. For that, use `expect(value).toMatchSnapshot()`. Test runner auto-detects the content type, and includes built-in matchers for text, png and jpeg images, and arbitrary binary data.
2021-05-28 17:02:23 -07:00
```js
// example.spec.js
const { test, expect } = require('playwright/test');
test('example test', async ({ page }) => {
await page.goto('https://playwright.dev');
expect(await page.screenshot()).toMatchSnapshot('optional-snapshot-name.png');
});
```
```ts
2021-05-27 20:30:03 -07:00
// example.spec.ts
import { test, expect } from 'playwright/test';
2021-05-27 20:30:03 -07:00
test('example test', async ({ page }) => {
await page.goto('https://playwright.dev');
expect(await page.screenshot()).toMatchSnapshot('optional-snapshot-name.png');
2021-05-27 20:30:03 -07:00
});
```
Snapshots are stored next to the test file, in a separate directory. For example, `my.spec.js` file will produce and store snapshots in the `my.spec.js-snapshots` directory. You should commit this directory to your version control (e.g. `git`), and review any changes to it.