Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
docs(test): mention webp as alternative snapshot format in toHaveScreenshot (#41782)
Yury Semikhatsky0d5a0a81d515
diff --git a/docs/src/api/class-locatorassertions.md b/docs/src/api/class-locatorassertions.mdindex 1c03272347..3a91e540a8 100644--- a/docs/src/api/class-locatorassertions.md+++ b/docs/src/api/class-locatorassertions.md@@ -1992,6 +1992,9 @@ yield the same result, and then compare the last screenshot with the expectation```jsconst 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.@@ -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@@ -2042,6 +2045,8 @@ Snapshot name.This function will wait until two consecutive locator screenshotsyield 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**```jsdiff --git a/docs/src/api/class-pageassertions.md b/docs/src/api/class-pageassertions.mdindex 2965f9a715..5747aa609b 100644--- a/docs/src/api/class-pageassertions.md+++ b/docs/src/api/class-pageassertions.md@@ -242,6 +242,9 @@ yield the same result, and then compare the last screenshot with the expectation```jsawait 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.@@ -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@@ -298,6 +301,8 @@ Snapshot name.This function will wait until two consecutive page screenshotsyield 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**```jsdiff --git a/docs/src/test-snapshots-js.md b/docs/src/test-snapshots-js.mdindex 5c64eccfbb..ed69bbcde2 100644--- a/docs/src/test-snapshots-js.md+++ b/docs/src/test-snapshots-js.md@@ -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.diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.tsindex 70a6d41cd0..d30c7f240d 100644--- a/packages/playwright/types/test.d.ts+++ b/packages/playwright/types/test.d.ts@@ -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?: {@@ -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@@ -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>;@@ -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