Skip to content

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

fix: support all commong screenshot options in toHaveScreenshot (#12670)

Andrey Lushnikove83549e8a09c
diff --git a/packages/playwright-core/src/protocol/channels.ts b/packages/playwright-core/src/protocol/channels.ts
index 72b3046941..c8c15e3307 100644
--- a/packages/playwright-core/src/protocol/channels.ts
+++ b/packages/playwright-core/src/protocol/channels.ts
@@ -1501,10 +1501,12 @@ export type PageExpectScreenshotParams = {
threshold?: number,
},
screenshotOptions?: {
- omitBackground?: boolean,
fullPage?: boolean,
- animations?: 'disabled' | 'allow',
clip?: Rect,
+ omitBackground?: boolean,
+ animations?: 'disabled' | 'allow',
+ size?: 'css' | 'device',
+ fonts?: 'ready' | 'nowait',
mask?: {
frame: FrameChannel,
selector: string,
@@ -1524,10 +1526,12 @@ export type PageExpectScreenshotOptions = {
threshold?: number,
},
screenshotOptions?: {
- omitBackground?: boolean,
fullPage?: boolean,
- animations?: 'disabled' | 'allow',
clip?: Rect,
+ omitBackground?: boolean,
+ animations?: 'disabled' | 'allow',
+ size?: 'css' | 'device',
+ fonts?: 'ready' | 'nowait',
mask?: {
frame: FrameChannel,
selector: string,
@@ -1545,10 +1549,10 @@ export type PageScreenshotParams = {
timeout?: number,
type?: 'png' | 'jpeg',
quality?: number,
- omitBackground?: boolean,
fullPage?: boolean,
- animations?: 'disabled' | 'allow',
clip?: Rect,
+ omitBackground?: boolean,
+ animations?: 'disabled' | 'allow',
size?: 'css' | 'device',
fonts?: 'ready' | 'nowait',
mask?: {
@@ -1560,10 +1564,10 @@ export type PageScreenshotOptions = {
timeout?: number,
type?: 'png' | 'jpeg',
quality?: number,
- omitBackground?: boolean,
fullPage?: boolean,
- animations?: 'disabled' | 'allow',
clip?: Rect,
+ omitBackground?: boolean,
+ animations?: 'disabled' | 'allow',
size?: 'css' | 'device',
fonts?: 'ready' | 'nowait',
mask?: {
diff --git a/packages/playwright-core/src/protocol/protocol.yml b/packages/playwright-core/src/protocol/protocol.yml
index 8f2ff845b6..db70c9a36b 100644
--- a/packages/playwright-core/src/protocol/protocol.yml
+++ b/packages/playwright-core/src/protocol/protocol.yml
@@ -309,6 +309,32 @@ LifecycleEvent:
- networkidle
- commit
+CommonScreenshotOptions:
+ type: mixin
+ properties:
+ omitBackground: boolean?
+ animations:
+ type: enum?
+ literals:
+ - disabled
+ - allow
+ size:
+ type: enum?
+ literals:
+ - css
+ - device
+ fonts:
+ type: enum?
+ literals:
+ - ready
+ - nowait
+ mask:
+ type: array?
+ items:
+ type: object
+ properties:
+ frame: Frame
+ selector: string
LaunchOptions:
type: mixin
@@ -1009,21 +1035,9 @@ Page:
screenshotOptions:
type: object?
properties:
- omitBackground: boolean?
fullPage: boolean?
- animations:
- type: enum?
- literals:
- - disabled
- - allow
clip: Rect?
- mask:
- type: array?
- items:
- type: object
- properties:
- frame: Frame
- selector: string
+ $mixin: CommonScreenshotOptions
returns:
diff: binary?
errorMessage: string?
@@ -1044,31 +1058,9 @@ Page:
- png
- jpeg
quality: number?
- omitBackground: boolean?
fullPage: boolean?
- animations:
- type: enum?
- literals:
- - disabled
- - allow
clip: Rect?
- size:
- type: enum?
- literals:
- - css
- - device
- fonts:
- type: enum?
- literals:
- - ready
- - nowait
- mask:
- type: array?
- items:
- type: object
- properties:
- frame: Frame
- selector: string
+ $mixin: CommonScreenshotOptions
returns:
binary: binary
tracing:
@@ -2221,29 +2213,7 @@ ElementHandle:
- png
- jpeg
quality: number?
- omitBackground: boolean?
- animations:
- type: enum?
- literals:
- - disabled
- - allow
- size:
- type: enum?
- literals:
- - css
- - device
- fonts:
- type: enum?
- literals:
- - ready
- - nowait
- mask:
- type: array?
- items:
- type: object
- properties:
- frame: Frame
- selector: string
+ $mixin: CommonScreenshotOptions
returns:
binary: binary
tracing:
diff --git a/packages/playwright-core/src/protocol/validator.ts b/packages/playwright-core/src/protocol/validator.ts
index 4266f4f31a..723c3f0507 100644
--- a/packages/playwright-core/src/protocol/validator.ts
+++ b/packages/playwright-core/src/protocol/validator.ts
@@ -554,10 +554,12 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
threshold: tOptional(tNumber),
})),
screenshotOptions: tOptional(tObject({
- omitBackground: tOptional(tBoolean),
fullPage: tOptional(tBoolean),
- animations: tOptional(tEnum(['disabled', 'allow'])),
clip: tOptional(tType('Rect')),
+ omitBackground: tOptional(tBoolean),
+ animations: tOptional(tEnum(['disabled', 'allow'])),
+ size: tOptional(tEnum(['css', 'device'])),
+ fonts: tOptional(tEnum(['ready', 'nowait'])),
mask: tOptional(tArray(tObject({
frame: tChannel('Frame'),
selector: tString,
@@ -568,10 +570,10 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
timeout: tOptional(tNumber),
type: tOptional(tEnum(['png', 'jpeg'])),
quality: tOptional(tNumber),
- omitBackground: tOptional(tBoolean),
fullPage: tOptional(tBoolean),
- animations: tOptional(tEnum(['disabled', 'allow'])),
clip: tOptional(tType('Rect')),
+ omitBackground: tOptional(tBoolean),
+ animations: tOptional(tEnum(['disabled', 'allow'])),
size: tOptional(tEnum(['css', 'device'])),
fonts: tOptional(tEnum(['ready', 'nowait'])),
mask: tOptional(tArray(tObject({