Skip to content

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

chore: page.screenshot() in bidi (#32671)

Yury Semikhatsky4c4d74ca5b98
diff --git a/packages/playwright-core/src/server/bidi/bidiPage.ts b/packages/playwright-core/src/server/bidi/bidiPage.ts
index 2f2e09441f..180e8a651e 100644
--- a/packages/playwright-core/src/server/bidi/bidiPage.ts
+++ b/packages/playwright-core/src/server/bidi/bidiPage.ts
@@ -404,7 +404,20 @@ export class BidiPage implements PageDelegate {
}
async takeScreenshot(progress: Progress, format: string, documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, scale: 'css' | 'device'): Promise<Buffer> {
- throw new Error('Method not implemented.');
+ const rect = (documentRect || viewportRect)!;
+ const { data } = await this._session.send('browsingContext.captureScreenshot', {
+ context: this._session.sessionId,
+ format: {
+ type: `image/${format === 'png' ? 'png' : 'jpeg'}`,
+ quality: quality || 80,
+ },
+ origin: documentRect ? 'document' : 'viewport',
+ clip: {
+ type: 'box',
+ ...rect,
+ }
+ });
+ return Buffer.from(data, 'base64');
}
async getContentFrame(handle: dom.ElementHandle): Promise<frames.Frame | null> {
diff --git a/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-bounding-box-bidi-chromium.png b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-bounding-box-bidi-chromium.png
new file mode 100644
index 0000000000..c2c3ddca29
Binary files /dev/null and b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-bounding-box-bidi-chromium.png differ
diff --git a/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-fractional-bidi-chromium.png b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-fractional-bidi-chromium.png
new file mode 100644
index 0000000000..35c53377f9
Binary files /dev/null and b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-fractional-bidi-chromium.png differ
diff --git a/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-fractional-offset-bidi-chromium.png b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-fractional-offset-bidi-chromium.png
new file mode 100644
index 0000000000..971561ba69
Binary files /dev/null and b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-fractional-offset-bidi-chromium.png differ
diff --git a/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-larger-than-viewport-bidi-chromium.png b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-larger-than-viewport-bidi-chromium.png
new file mode 100644
index 0000000000..52c1bb2b92
Binary files /dev/null and b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-larger-than-viewport-bidi-chromium.png differ
diff --git a/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-padding-border-bidi-chromium.png b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-padding-border-bidi-chromium.png
new file mode 100644
index 0000000000..fc34319896
Binary files /dev/null and b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-padding-border-bidi-chromium.png differ
diff --git a/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-rotate-bidi-chromium.png b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-rotate-bidi-chromium.png
new file mode 100644
index 0000000000..5aab14c4b9
Binary files /dev/null and b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-rotate-bidi-chromium.png differ
diff --git a/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-scrolled-into-view-bidi-chromium.png b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-scrolled-into-view-bidi-chromium.png
new file mode 100644
index 0000000000..fc34319896
Binary files /dev/null and b/tests/page/elementhandle-screenshot.spec.ts-snapshots/screenshot-element-scrolled-into-view-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-0-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-0-bidi-chromium.png
new file mode 100644
index 0000000000..6fcce2cf53
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-0-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-1-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-1-bidi-chromium.png
new file mode 100644
index 0000000000..f6f130a44a
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-1-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-2-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-2-bidi-chromium.png
new file mode 100644
index 0000000000..ecabd8b22d
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-2-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/grid-cell-1-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/grid-cell-1-bidi-chromium.png
new file mode 100644
index 0000000000..2eab11668d
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/grid-cell-1-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/hide-should-work-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/hide-should-work-bidi-chromium.png
new file mode 100644
index 0000000000..dd0549a411
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/hide-should-work-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/mask-color-should-work-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/mask-color-should-work-bidi-chromium.png
new file mode 100644
index 0000000000..fef9e17ffe
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/mask-color-should-work-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/mask-should-work-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/mask-should-work-bidi-chromium.png
new file mode 100644
index 0000000000..c663e342dc
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/mask-should-work-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/mask-should-work-with-elementhandle-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/mask-should-work-with-elementhandle-bidi-chromium.png
new file mode 100644
index 0000000000..5a13aac48b
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/mask-should-work-with-elementhandle-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/mask-should-work-with-locator-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/mask-should-work-with-locator-bidi-chromium.png
new file mode 100644
index 0000000000..5a13aac48b
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/mask-should-work-with-locator-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/page-screenshot-should-capture-css-transform-1-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/page-screenshot-should-capture-css-transform-1-bidi-chromium.png
new file mode 100644
index 0000000000..d29a2b4ab2
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/page-screenshot-should-capture-css-transform-1-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/remove-should-work-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/remove-should-work-bidi-chromium.png
new file mode 100644
index 0000000000..d35ddd4289
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/remove-should-work-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/screenshot-canvas-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-canvas-bidi-chromium.png
new file mode 100644
index 0000000000..dfafbda638
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-canvas-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/screenshot-canvas-text-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-canvas-text-bidi-chromium.png
new file mode 100644
index 0000000000..0971000b5f
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-canvas-text-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/screenshot-clip-odd-size-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-clip-odd-size-bidi-chromium.png
new file mode 100644
index 0000000000..61c0b7044a
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-clip-odd-size-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/screenshot-clip-rect-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-clip-rect-bidi-chromium.png
new file mode 100644
index 0000000000..8c4046910b
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-clip-rect-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/screenshot-grid-fullpage-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-grid-fullpage-bidi-chromium.png
new file mode 100644
index 0000000000..0354694da1
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-grid-fullpage-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/screenshot-grid-fullpage-mask-outside-viewport-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-grid-fullpage-mask-outside-viewport-bidi-chromium.png
new file mode 100644
index 0000000000..9e97bfcedb
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-grid-fullpage-mask-outside-viewport-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/screenshot-iframe-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-iframe-bidi-chromium.png
new file mode 100644
index 0000000000..56aa8706bb
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-iframe-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/screenshot-offscreen-clip-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-offscreen-clip-bidi-chromium.png
new file mode 100644
index 0000000000..21f7b0f461
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-offscreen-clip-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/screenshot-sanity-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-sanity-bidi-chromium.png
new file mode 100644
index 0000000000..122a4f0ae0
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-sanity-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/screenshot-translateZ-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-translateZ-bidi-chromium.png
new file mode 100644
index 0000000000..e3f5642e60
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-translateZ-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/screenshot-web-font-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-web-font-bidi-chromium.png
new file mode 100644
index 0000000000..40aa6d483c
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-web-font-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/screenshot-webgl-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-webgl-bidi-chromium.png
new file mode 100644
index 0000000000..76109512b5
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/screenshot-webgl-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/should-capture-css-box-shadow-1-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/should-capture-css-box-shadow-1-bidi-chromium.png
new file mode 100644
index 0000000000..089549eb3c
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/should-capture-css-box-shadow-1-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/should-mask-in-parallel-1-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/should-mask-in-parallel-1-bidi-chromium.png
new file mode 100644
index 0000000000..18f4ed1e60
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/should-mask-in-parallel-1-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/should-mask-in-parallel-2-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/should-mask-in-parallel-2-bidi-chromium.png
new file mode 100644
index 0000000000..bf3dbe65bd
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/should-mask-in-parallel-2-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/should-mask-inside-iframe-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/should-mask-inside-iframe-bidi-chromium.png
new file mode 100644
index 0000000000..c663e342dc
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/should-mask-inside-iframe-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/should-mask-multiple-elements-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/should-mask-multiple-elements-bidi-chromium.png
new file mode 100644
index 0000000000..0ff0cf5137
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/should-mask-multiple-elements-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/transparent-bidi-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/transparent-bidi-chromium.png
new file mode 100644
index 0000000000..b9aa8f7a72
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/transparent-bidi-chromium.png differ
diff --git a/tests/page/page-screenshot.spec.ts-snapshots/white-bidi-chromium.jpg b/tests/page/page-screenshot.spec.ts-snapshots/white-bidi-chromium.jpg
new file mode 100644
index 0000000000..ed816ce766
Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/white-bidi-chromium.jpg differ