Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion docs/src/api/class-locatorassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,9 @@ yield the same result, and then compare the last screenshot with the expectation
```js
const locator = page.getByRole('button');
await expect(locator).toHaveScreenshot('image.png');

// Store the snapshot in the WebP format.
await expect(locator).toHaveScreenshot('image.webp');
```

Note that screenshot assertions only work with Playwright test runner.
Expand All @@ -2000,7 +2003,7 @@ Note that screenshot assertions only work with Playwright test runner.
* since: v1.23
- `name` <[string]|[Array]<[string]>>

Snapshot name.
Snapshot name. Must have a `.png` or `.webp` extension, the screenshot is captured in the corresponding format. Both formats are lossless.

### option: LocatorAssertions.toHaveScreenshot#1.timeout = %%-js-assertions-timeout-%%
* since: v1.23
Expand Down Expand Up @@ -2042,6 +2045,8 @@ Snapshot name.
This function will wait until two consecutive locator screenshots
yield the same result, and then compare the last screenshot with the expectation.

The snapshot is stored in the PNG format. To store it in the WebP format instead, pass a snapshot name with the `.webp` extension.

**Usage**

```js
Expand Down
7 changes: 6 additions & 1 deletion docs/src/api/class-pageassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ yield the same result, and then compare the last screenshot with the expectation

```js
await expect(page).toHaveScreenshot('image.png');

// Store the snapshot in the WebP format.
await expect(page).toHaveScreenshot('image.webp');
```

Note that screenshot assertions only work with Playwright test runner.
Expand All @@ -250,7 +253,7 @@ Note that screenshot assertions only work with Playwright test runner.
* since: v1.23
- `name` <[string]|[Array]<[string]>>

Snapshot name.
Snapshot name. Must have a `.png` or `.webp` extension, the screenshot is captured in the corresponding format. Both formats are lossless.

### option: PageAssertions.toHaveScreenshot#1.timeout = %%-js-assertions-timeout-%%
* since: v1.23
Expand Down Expand Up @@ -298,6 +301,8 @@ Snapshot name.
This function will wait until two consecutive page screenshots
yield the same result, and then compare the last screenshot with the expectation.

The snapshot is stored in the PNG format. To store it in the WebP format instead, pass a snapshot name with the `.webp` extension.

**Usage**

```js
Expand Down
6 changes: 6 additions & 0 deletions docs/src/test-snapshots-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ The snapshot name `example-test-1-chromium-darwin.png` consists of a few parts:

The snapshot name and path can be configured with [`property: TestConfig.snapshotPathTemplate`] in the playwright config.

Snapshots are stored as PNG by default. Give the snapshot a name with the `.webp` extension to store it in the WebP format instead, it is also lossless:

```js
await expect(page).toHaveScreenshot('landing.webp');
```

> Note that `toHaveScreenshot()` also accepts an array of path segments to the snapshot file such as `expect().toHaveScreenshot(['relative', 'path', 'to', 'snapshot.png'])`.
> However, this path must stay within the snapshots directory for each test file (i.e. `a.spec.js-snapshots`), otherwise it will throw.

Expand Down
18 changes: 16 additions & 2 deletions packages/playwright/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9549,10 +9549,14 @@ interface LocatorAssertions {
* ```js
* const locator = page.getByRole('button');
* await expect(locator).toHaveScreenshot('image.png');
*
* // Store the snapshot in the WebP format.
* await expect(locator).toHaveScreenshot('image.webp');
* ```
*
* Note that screenshot assertions only work with Playwright test runner.
* @param name Snapshot name.
* @param name Snapshot name. Must have a `.png` or `.webp` extension, the screenshot is captured in the corresponding format.
* Both formats are lossless.
* @param options
*/
toHaveScreenshot(name: string|ReadonlyArray<string>, options?: {
Expand Down Expand Up @@ -9638,6 +9642,9 @@ interface LocatorAssertions {
* This function will wait until two consecutive locator screenshots yield the same result, and then compare the last
* screenshot with the expectation.
*
* The snapshot is stored in the PNG format. To store it in the WebP format instead, pass a snapshot name with the
* `.webp` extension.
*
* **Usage**
*
* ```js
Expand Down Expand Up @@ -9976,10 +9983,14 @@ interface PageAssertions {
*
* ```js
* await expect(page).toHaveScreenshot('image.png');
*
* // Store the snapshot in the WebP format.
* await expect(page).toHaveScreenshot('image.webp');
* ```
*
* Note that screenshot assertions only work with Playwright test runner.
* @param name Snapshot name.
* @param name Snapshot name. Must have a `.png` or `.webp` extension, the screenshot is captured in the corresponding format.
* Both formats are lossless.
* @param options
*/
toHaveScreenshot(name: string|ReadonlyArray<string>, options?: PageAssertionsToHaveScreenshotOptions): Promise<void>;
Expand All @@ -9988,6 +9999,9 @@ interface PageAssertions {
* This function will wait until two consecutive page screenshots yield the same result, and then compare the last
* screenshot with the expectation.
*
* The snapshot is stored in the PNG format. To store it in the WebP format instead, pass a snapshot name with the
* `.webp` extension.
*
* **Usage**
*
* ```js
Expand Down
Loading