Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix: expect.toHaveScreenshot.animations types (#14387)

Ross Wollman9b225f2ad40e
diff --git a/docs/src/test-api/class-testconfig.md b/docs/src/test-api/class-testconfig.md
index 88142dc48f..388cc0f543 100644
--- a/docs/src/test-api/class-testconfig.md
+++ b/docs/src/test-api/class-testconfig.md
@@ -40,7 +40,7 @@ export default config;
- `threshold` ?<[float]> an acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the same pixel in compared images, between zero (strict) and one (lax). Defaults to `0.2`.
- `maxDiffPixels` ?<[int]> an acceptable amount of pixels that could be different, unset by default.
- `maxDiffPixelRatio` ?<[float]> an acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1` , unset by default.
- - `animations` ?<[ScreenshotAnimations]<"allow"|"disable">> See [`option: animations`] in [`method: Page.screenshot`]. Defaults to `"disable"`.
+ - `animations` ?<[ScreenshotAnimations]<"allow"|"disabled">> See [`option: animations`] in [`method: Page.screenshot`]. Defaults to `"disabled"`.
- `caret` ?<[ScreenshotCaret]<"hide"|"initial">> See [`option: caret`] in [`method: Page.screenshot`]. Defaults to `"hide"`.
- `scale` ?<[ScreenshotScale]<"css"|"device">> See [`option: scale`] in [`method: Page.screenshot`]. Defaults to `"css"`.
- `toMatchSnapshot` ?<[Object]> Configuration for the [`method: ScreenshotAssertions.toMatchSnapshot#1`] method.
diff --git a/docs/src/test-api/class-testproject.md b/docs/src/test-api/class-testproject.md
index 04a7842a23..f5ec00dda4 100644
--- a/docs/src/test-api/class-testproject.md
+++ b/docs/src/test-api/class-testproject.md
@@ -111,7 +111,7 @@ export default config;
- `threshold` ?<[float]> an acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the same pixel in compared images, between zero (strict) and one (lax). Defaults to `0.2`.
- `maxDiffPixels` ?<[int]> an acceptable amount of pixels that could be different, unset by default.
- `maxDiffPixelRatio` ?<[float]> an acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1` , unset by default.
- - `animations` ?<[ScreenshotAnimations]<"allow"|"disable">> See [`option: animations`] in [`method: Page.screenshot`]. Defaults to `"disable"`.
+ - `animations` ?<[ScreenshotAnimations]<"allow"|"disabled">> See [`option: animations`] in [`method: Page.screenshot`]. Defaults to `"disabled"`.
- `caret` ?<[ScreenshotCaret]<"hide"|"initial">> See [`option: caret`] in [`method: Page.screenshot`]. Defaults to `"hide"`.
- `scale` ?<[ScreenshotScale]<"css"|"device">> See [`option: scale`] in [`method: Page.screenshot`]. Defaults to `"css"`.
- `toMatchSnapshot` ?<[Object]> Configuration for the [`method: ScreenshotAssertions.toMatchSnapshot#1`] method.
diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts
index 0471a948a1..5fdc4ea041 100644
--- a/packages/playwright-test/types/test.d.ts
+++ b/packages/playwright-test/types/test.d.ts
@@ -508,9 +508,9 @@ interface TestConfig {
/**
* See `animations` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults
- * to `"disable"`.
+ * to `"disabled"`.
*/
- animations?: "allow"|"disable";
+ animations?: "allow"|"disabled";
/**
* See `caret` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults to
@@ -4020,9 +4020,9 @@ interface TestProject {
/**
* See `animations` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults
- * to `"disable"`.
+ * to `"disabled"`.
*/
- animations?: "allow"|"disable";
+ animations?: "allow"|"disabled";
/**
* See `caret` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults to
diff --git a/tests/config/experimental.d.ts b/tests/config/experimental.d.ts
index a625fd1eca..4077ff0882 100644
--- a/tests/config/experimental.d.ts
+++ b/tests/config/experimental.d.ts
@@ -16690,9 +16690,9 @@ interface TestConfig {
/**
* See `animations` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults
- * to `"disable"`.
+ * to `"disabled"`.
*/
- animations?: "allow"|"disable";
+ animations?: "allow"|"disabled";
/**
* See `caret` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults to
@@ -20232,9 +20232,9 @@ interface TestProject {
/**
* See `animations` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults
- * to `"disable"`.
+ * to `"disabled"`.
*/
- animations?: "allow"|"disable";
+ animations?: "allow"|"disabled";
/**
* See `caret` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults to
diff --git a/tests/playwright-test/to-have-screenshot.spec.ts b/tests/playwright-test/to-have-screenshot.spec.ts
index db718ac093..b848864af8 100644
--- a/tests/playwright-test/to-have-screenshot.spec.ts
+++ b/tests/playwright-test/to-have-screenshot.spec.ts
@@ -74,6 +74,42 @@ test('should disable animations by default', async ({ runInlineTest }, testInfo)
expect(result.exitCode).toBe(0);
});
+test.describe('expect config animations option', () => {
+ test('disabled', async ({ runInlineTest }, testInfo) => {
+ const cssTransitionURL = pathToFileURL(path.join(__dirname, '../assets/css-transition.html'));
+ const result = await runInlineTest({
+ ...playwrightConfig({
+ expect: { toHaveScreenshot: { animations: 'disabled' } },
+ }),
+ 'a.spec.js': `
+ pwt.test('is a test', async ({ page }) => {
+ await page.goto('${cssTransitionURL}');
+ await expect(page).toHaveScreenshot({ timeout: 2000 });
+ });
+ `
+ }, { 'update-snapshots': true });
+ expect(result.exitCode).toBe(0);
+ });
+
+ test('allow', async ({ runInlineTest }, testInfo) => {
+ const cssTransitionURL = pathToFileURL(path.join(__dirname, '../assets/css-transition.html'));
+ const result = await runInlineTest({
+ ...playwrightConfig({
+ expect: { toHaveScreenshot: { animations: 'allow' } },
+ }),
+ 'a.spec.js': `
+ pwt.test('is a test', async ({ page }) => {
+ await page.goto('${cssTransitionURL}');
+ await expect(page).toHaveScreenshot({ timeout: 2000 });
+ });
+ `
+ }, { 'update-snapshots': true });
+ expect(result.exitCode).toBe(1);
+ expect(result.output).toContain('is-a-test-1-diff.png');
+ });
+});
+
+
test('should fail with proper error when unsupported argument is given', async ({ runInlineTest }, testInfo) => {
const cssTransitionURL = pathToFileURL(path.join(__dirname, '../assets/css-transition.html'));
const result = await runInlineTest({