Skip to content
This repository was archived by the owner on Jun 11, 2021. It is now read-only.

Commit b51a775

Browse files
authoredOct 26, 2020
docs(readme): assertions for visual comparisons (#171)
1 parent a4b78c3 commit b51a775

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed
 

‎README.md

+25-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Playwright test runner is **available in preview** and minor breaking changes co
1212
- [Multiple pages](#multiple-pages)
1313
- [Mobile emulation](#mobile-emulation)
1414
- [Network mocking](#network-mocking)
15+
- [Visual comparisons](#visual-comparisons)
1516
- [Configuration](#configuration)
1617
- [Modify context options](#modify-context-options)
1718
- [JUnit reporter](#junit-reporter)
@@ -175,6 +176,27 @@ it('loads pages without css requests', async ({ mockedContext }) => {
175176
});
176177
```
177178

179+
### Visual comparisons
180+
181+
The `expect` API supports visual comparisons with `toMatchSnapshot`. This uses the [pixelmatch](https://github.com/mapbox/pixelmatch) library, and you can pass `threshold` as an option.
182+
183+
```js
184+
import { it, expect } from '@playwright/test';
185+
186+
it('compares page screenshot', async ({ page, browserName }) => {
187+
await page.goto('https://stackoverflow.com');
188+
const screenshot = await page.screenshot();
189+
expect(screenshot).toMatchSnapshot(`test-${browserName}.png`, { threshold: 0.2 });
190+
});
191+
```
192+
193+
On first execution, this will generate golden snapshots. Subsequent runs will compare against the golden snapshots. To update golden snapshots with new actuals, run with the `--update-snapshots` flag.
194+
195+
```sh
196+
# Update golden snapshots when they differ from actual
197+
npx folio --update-snapshots
198+
```
199+
178200
-----------
179201

180202
## Configuration
@@ -196,7 +218,7 @@ const builder = baseFolio.extend();
196218
const folio = builder.build();
197219
```
198220

199-
**Step 2**: Override the existing `contextOptions` fixture to add a custom viewport size.
221+
**Step 2**: Override the existing `contextOptions` fixture to configure viewport size and HTTPS error handling.
200222

201223
```diff
202224
// test/fixtures.ts
@@ -208,7 +230,8 @@ const builder = baseFolio.extend();
208230
+ builder.contextOptions.override(async ({ contextOptions }, runTest) => {
209231
+ const modifiedOptions: BrowserContextOptions = {
210232
+ ...contextOptions, // Default options
211-
+ viewport: { width: 1440, height: 900 } // Overrides
233+
+ viewport: { width: 1440, height: 900 },
234+
+ ignoreHTTPSErrors: true
212235
+ }
213236
+ await runTest(modifiedOptions);
214237
+ });

0 commit comments

Comments
 (0)
Failed to load comments.