feat(screenshot): rename "size" option to "scale" (#13254)
Drive-by: fix `caret` handling in `toHaveScreenshot`.
This commit is contained in:
parent
2eb1c8bc42
commit
a200fe3528
|
|
@ -954,8 +954,8 @@ When true, takes a screenshot of the full scrollable page, instead of the curren
|
||||||
|
|
||||||
An object which specifies clipping of the resulting image. Should have the following fields:
|
An object which specifies clipping of the resulting image. Should have the following fields:
|
||||||
|
|
||||||
## screenshot-option-size
|
## screenshot-option-scale
|
||||||
- `size` <[ScreenshotSize]<"css"|"device">>
|
- `scale` <[ScreenshotScale]<"css"|"device">>
|
||||||
|
|
||||||
When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenhots of high-dpi devices will be twice as large or even larger. Defaults to `"device"`.
|
When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenhots of high-dpi devices will be twice as large or even larger. Defaults to `"device"`.
|
||||||
|
|
||||||
|
|
@ -974,7 +974,7 @@ When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`,
|
||||||
- %%-screenshot-option-omit-background-%%
|
- %%-screenshot-option-omit-background-%%
|
||||||
- %%-screenshot-option-quality-%%
|
- %%-screenshot-option-quality-%%
|
||||||
- %%-screenshot-option-path-%%
|
- %%-screenshot-option-path-%%
|
||||||
- %%-screenshot-option-size-%%
|
- %%-screenshot-option-scale-%%
|
||||||
- %%-screenshot-option-fonts-%%
|
- %%-screenshot-option-fonts-%%
|
||||||
- %%-screenshot-option-caret-%%
|
- %%-screenshot-option-caret-%%
|
||||||
- %%-screenshot-option-type-%%
|
- %%-screenshot-option-type-%%
|
||||||
|
|
|
||||||
|
|
@ -1519,7 +1519,7 @@ export type PageExpectScreenshotParams = {
|
||||||
omitBackground?: boolean,
|
omitBackground?: boolean,
|
||||||
caret?: 'hide' | 'initial',
|
caret?: 'hide' | 'initial',
|
||||||
animations?: 'disabled' | 'allow',
|
animations?: 'disabled' | 'allow',
|
||||||
size?: 'css' | 'device',
|
scale?: 'css' | 'device',
|
||||||
fonts?: 'ready' | 'nowait',
|
fonts?: 'ready' | 'nowait',
|
||||||
mask?: {
|
mask?: {
|
||||||
frame: FrameChannel,
|
frame: FrameChannel,
|
||||||
|
|
@ -1545,7 +1545,7 @@ export type PageExpectScreenshotOptions = {
|
||||||
omitBackground?: boolean,
|
omitBackground?: boolean,
|
||||||
caret?: 'hide' | 'initial',
|
caret?: 'hide' | 'initial',
|
||||||
animations?: 'disabled' | 'allow',
|
animations?: 'disabled' | 'allow',
|
||||||
size?: 'css' | 'device',
|
scale?: 'css' | 'device',
|
||||||
fonts?: 'ready' | 'nowait',
|
fonts?: 'ready' | 'nowait',
|
||||||
mask?: {
|
mask?: {
|
||||||
frame: FrameChannel,
|
frame: FrameChannel,
|
||||||
|
|
@ -1569,7 +1569,7 @@ export type PageScreenshotParams = {
|
||||||
omitBackground?: boolean,
|
omitBackground?: boolean,
|
||||||
caret?: 'hide' | 'initial',
|
caret?: 'hide' | 'initial',
|
||||||
animations?: 'disabled' | 'allow',
|
animations?: 'disabled' | 'allow',
|
||||||
size?: 'css' | 'device',
|
scale?: 'css' | 'device',
|
||||||
fonts?: 'ready' | 'nowait',
|
fonts?: 'ready' | 'nowait',
|
||||||
mask?: {
|
mask?: {
|
||||||
frame: FrameChannel,
|
frame: FrameChannel,
|
||||||
|
|
@ -1585,7 +1585,7 @@ export type PageScreenshotOptions = {
|
||||||
omitBackground?: boolean,
|
omitBackground?: boolean,
|
||||||
caret?: 'hide' | 'initial',
|
caret?: 'hide' | 'initial',
|
||||||
animations?: 'disabled' | 'allow',
|
animations?: 'disabled' | 'allow',
|
||||||
size?: 'css' | 'device',
|
scale?: 'css' | 'device',
|
||||||
fonts?: 'ready' | 'nowait',
|
fonts?: 'ready' | 'nowait',
|
||||||
mask?: {
|
mask?: {
|
||||||
frame: FrameChannel,
|
frame: FrameChannel,
|
||||||
|
|
@ -2905,7 +2905,7 @@ export type ElementHandleScreenshotParams = {
|
||||||
omitBackground?: boolean,
|
omitBackground?: boolean,
|
||||||
caret?: 'hide' | 'initial',
|
caret?: 'hide' | 'initial',
|
||||||
animations?: 'disabled' | 'allow',
|
animations?: 'disabled' | 'allow',
|
||||||
size?: 'css' | 'device',
|
scale?: 'css' | 'device',
|
||||||
fonts?: 'ready' | 'nowait',
|
fonts?: 'ready' | 'nowait',
|
||||||
mask?: {
|
mask?: {
|
||||||
frame: FrameChannel,
|
frame: FrameChannel,
|
||||||
|
|
@ -2919,7 +2919,7 @@ export type ElementHandleScreenshotOptions = {
|
||||||
omitBackground?: boolean,
|
omitBackground?: boolean,
|
||||||
caret?: 'hide' | 'initial',
|
caret?: 'hide' | 'initial',
|
||||||
animations?: 'disabled' | 'allow',
|
animations?: 'disabled' | 'allow',
|
||||||
size?: 'css' | 'device',
|
scale?: 'css' | 'device',
|
||||||
fonts?: 'ready' | 'nowait',
|
fonts?: 'ready' | 'nowait',
|
||||||
mask?: {
|
mask?: {
|
||||||
frame: FrameChannel,
|
frame: FrameChannel,
|
||||||
|
|
|
||||||
|
|
@ -323,7 +323,7 @@ CommonScreenshotOptions:
|
||||||
literals:
|
literals:
|
||||||
- disabled
|
- disabled
|
||||||
- allow
|
- allow
|
||||||
size:
|
scale:
|
||||||
type: enum?
|
type: enum?
|
||||||
literals:
|
literals:
|
||||||
- css
|
- css
|
||||||
|
|
|
||||||
|
|
@ -563,7 +563,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
|
||||||
omitBackground: tOptional(tBoolean),
|
omitBackground: tOptional(tBoolean),
|
||||||
caret: tOptional(tEnum(['hide', 'initial'])),
|
caret: tOptional(tEnum(['hide', 'initial'])),
|
||||||
animations: tOptional(tEnum(['disabled', 'allow'])),
|
animations: tOptional(tEnum(['disabled', 'allow'])),
|
||||||
size: tOptional(tEnum(['css', 'device'])),
|
scale: tOptional(tEnum(['css', 'device'])),
|
||||||
fonts: tOptional(tEnum(['ready', 'nowait'])),
|
fonts: tOptional(tEnum(['ready', 'nowait'])),
|
||||||
mask: tOptional(tArray(tObject({
|
mask: tOptional(tArray(tObject({
|
||||||
frame: tChannel('Frame'),
|
frame: tChannel('Frame'),
|
||||||
|
|
@ -580,7 +580,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
|
||||||
omitBackground: tOptional(tBoolean),
|
omitBackground: tOptional(tBoolean),
|
||||||
caret: tOptional(tEnum(['hide', 'initial'])),
|
caret: tOptional(tEnum(['hide', 'initial'])),
|
||||||
animations: tOptional(tEnum(['disabled', 'allow'])),
|
animations: tOptional(tEnum(['disabled', 'allow'])),
|
||||||
size: tOptional(tEnum(['css', 'device'])),
|
scale: tOptional(tEnum(['css', 'device'])),
|
||||||
fonts: tOptional(tEnum(['ready', 'nowait'])),
|
fonts: tOptional(tEnum(['ready', 'nowait'])),
|
||||||
mask: tOptional(tArray(tObject({
|
mask: tOptional(tArray(tObject({
|
||||||
frame: tChannel('Frame'),
|
frame: tChannel('Frame'),
|
||||||
|
|
@ -1085,7 +1085,7 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
|
||||||
omitBackground: tOptional(tBoolean),
|
omitBackground: tOptional(tBoolean),
|
||||||
caret: tOptional(tEnum(['hide', 'initial'])),
|
caret: tOptional(tEnum(['hide', 'initial'])),
|
||||||
animations: tOptional(tEnum(['disabled', 'allow'])),
|
animations: tOptional(tEnum(['disabled', 'allow'])),
|
||||||
size: tOptional(tEnum(['css', 'device'])),
|
scale: tOptional(tEnum(['css', 'device'])),
|
||||||
fonts: tOptional(tEnum(['ready', 'nowait'])),
|
fonts: tOptional(tEnum(['ready', 'nowait'])),
|
||||||
mask: tOptional(tArray(tObject({
|
mask: tOptional(tArray(tObject({
|
||||||
frame: tChannel('Frame'),
|
frame: tChannel('Frame'),
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ export class CRPage implements PageDelegate {
|
||||||
await this._mainFrameSession._client.send('Emulation.setDefaultBackgroundColorOverride', { color });
|
await this._mainFrameSession._client.send('Emulation.setDefaultBackgroundColorOverride', { color });
|
||||||
}
|
}
|
||||||
|
|
||||||
async takeScreenshot(progress: Progress, format: 'png' | 'jpeg', documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, size: 'css' | 'device'): Promise<Buffer> {
|
async takeScreenshot(progress: Progress, format: 'png' | 'jpeg', documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, scale: 'css' | 'device'): Promise<Buffer> {
|
||||||
const { visualViewport } = await this._mainFrameSession._client.send('Page.getLayoutMetrics');
|
const { visualViewport } = await this._mainFrameSession._client.send('Page.getLayoutMetrics');
|
||||||
if (!documentRect) {
|
if (!documentRect) {
|
||||||
documentRect = {
|
documentRect = {
|
||||||
|
|
@ -267,7 +267,7 @@ export class CRPage implements PageDelegate {
|
||||||
// When taking screenshots with documentRect (based on the page content, not viewport),
|
// When taking screenshots with documentRect (based on the page content, not viewport),
|
||||||
// ignore current page scale.
|
// ignore current page scale.
|
||||||
const clip = { ...documentRect, scale: viewportRect ? visualViewport.scale : 1 };
|
const clip = { ...documentRect, scale: viewportRect ? visualViewport.scale : 1 };
|
||||||
if (size === 'css') {
|
if (scale === 'css') {
|
||||||
const deviceScaleFactor = this._browserContext._options.deviceScaleFactor || 1;
|
const deviceScaleFactor = this._browserContext._options.deviceScaleFactor || 1;
|
||||||
clip.scale /= deviceScaleFactor;
|
clip.scale /= deviceScaleFactor;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -412,7 +412,7 @@ export class FFPage implements PageDelegate {
|
||||||
throw new Error('Not implemented');
|
throw new Error('Not implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
async takeScreenshot(progress: Progress, format: 'png' | 'jpeg', documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, size: 'css' | 'device'): Promise<Buffer> {
|
async takeScreenshot(progress: Progress, format: 'png' | 'jpeg', documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, scale: 'css' | 'device'): Promise<Buffer> {
|
||||||
if (!documentRect) {
|
if (!documentRect) {
|
||||||
const scrollOffset = await this._page.mainFrame().waitForFunctionValueInUtility(progress, () => ({ x: window.scrollX, y: window.scrollY }));
|
const scrollOffset = await this._page.mainFrame().waitForFunctionValueInUtility(progress, () => ({ x: window.scrollX, y: window.scrollY }));
|
||||||
documentRect = {
|
documentRect = {
|
||||||
|
|
@ -428,7 +428,7 @@ export class FFPage implements PageDelegate {
|
||||||
const { data } = await this._session.send('Page.screenshot', {
|
const { data } = await this._session.send('Page.screenshot', {
|
||||||
mimeType: ('image/' + format) as ('image/png' | 'image/jpeg'),
|
mimeType: ('image/' + format) as ('image/png' | 'image/jpeg'),
|
||||||
clip: documentRect,
|
clip: documentRect,
|
||||||
omitDeviceScaleFactor: size === 'css',
|
omitDeviceScaleFactor: scale === 'css',
|
||||||
});
|
});
|
||||||
return Buffer.from(data, 'base64');
|
return Buffer.from(data, 'base64');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ export interface PageDelegate {
|
||||||
bringToFront(): Promise<void>;
|
bringToFront(): Promise<void>;
|
||||||
|
|
||||||
setBackgroundColor(color?: { r: number; g: number; b: number; a: number; }): Promise<void>;
|
setBackgroundColor(color?: { r: number; g: number; b: number; a: number; }): Promise<void>;
|
||||||
takeScreenshot(progress: Progress, format: string, documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, size: 'css' | 'device'): Promise<Buffer>;
|
takeScreenshot(progress: Progress, format: string, documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, scale: 'css' | 'device'): Promise<Buffer>;
|
||||||
|
|
||||||
isElementHandle(remoteObject: any): boolean;
|
isElementHandle(remoteObject: any): boolean;
|
||||||
adoptElementHandle<T extends Node>(handle: dom.ElementHandle<T>, to: dom.FrameExecutionContext): Promise<dom.ElementHandle<T>>;
|
adoptElementHandle<T extends Node>(handle: dom.ElementHandle<T>, to: dom.FrameExecutionContext): Promise<dom.ElementHandle<T>>;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ export type ScreenshotOptions = {
|
||||||
mask?: { frame: Frame, selector: string}[],
|
mask?: { frame: Frame, selector: string}[],
|
||||||
fullPage?: boolean,
|
fullPage?: boolean,
|
||||||
clip?: Rect,
|
clip?: Rect,
|
||||||
size?: 'css' | 'device',
|
scale?: 'css' | 'device',
|
||||||
fonts?: 'ready' | 'nowait',
|
fonts?: 'ready' | 'nowait',
|
||||||
caret?: 'hide' | 'initial',
|
caret?: 'hide' | 'initial',
|
||||||
};
|
};
|
||||||
|
|
@ -278,7 +278,7 @@ export class Screenshotter {
|
||||||
const cleanupHighlight = await this._maskElements(progress, options);
|
const cleanupHighlight = await this._maskElements(progress, options);
|
||||||
progress.throwIfAborted(); // Avoid extra work.
|
progress.throwIfAborted(); // Avoid extra work.
|
||||||
|
|
||||||
const buffer = await this._page._delegate.takeScreenshot(progress, format, documentRect, viewportRect, options.quality, fitsViewport, options.size || 'device');
|
const buffer = await this._page._delegate.takeScreenshot(progress, format, documentRect, viewportRect, options.quality, fitsViewport, options.scale || 'device');
|
||||||
progress.throwIfAborted(); // Avoid restoring after failure - should be done by cleanup.
|
progress.throwIfAborted(); // Avoid restoring after failure - should be done by cleanup.
|
||||||
|
|
||||||
await cleanupHighlight();
|
await cleanupHighlight();
|
||||||
|
|
|
||||||
|
|
@ -821,9 +821,9 @@ export class WKPage implements PageDelegate {
|
||||||
this._recordingVideoFile = null;
|
this._recordingVideoFile = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async takeScreenshot(progress: Progress, format: string, documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, size: 'css' | 'device'): Promise<Buffer> {
|
async takeScreenshot(progress: Progress, format: string, documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined, fitsViewport: boolean, scale: 'css' | 'device'): Promise<Buffer> {
|
||||||
const rect = (documentRect || viewportRect)!;
|
const rect = (documentRect || viewportRect)!;
|
||||||
const result = await this._session.send('Page.snapshotRect', { ...rect, coordinateSystem: documentRect ? 'Page' : 'Viewport', omitDeviceScaleFactor: size === 'css' });
|
const result = await this._session.send('Page.snapshotRect', { ...rect, coordinateSystem: documentRect ? 'Page' : 'Viewport', omitDeviceScaleFactor: scale === 'css' });
|
||||||
const prefix = 'data:image/png;base64,';
|
const prefix = 'data:image/png;base64,';
|
||||||
let buffer = Buffer.from(result.dataURL.substr(prefix.length), 'base64');
|
let buffer = Buffer.from(result.dataURL.substr(prefix.length), 'base64');
|
||||||
if (format === 'jpeg')
|
if (format === 'jpeg')
|
||||||
|
|
|
||||||
6
packages/playwright-core/types/types.d.ts
vendored
6
packages/playwright-core/types/types.d.ts
vendored
|
|
@ -8188,7 +8188,7 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
|
||||||
* keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenhots of
|
* keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenhots of
|
||||||
* high-dpi devices will be twice as large or even larger. Defaults to `"device"`.
|
* high-dpi devices will be twice as large or even larger. Defaults to `"device"`.
|
||||||
*/
|
*/
|
||||||
size?: "css"|"device";
|
scale?: "css"|"device";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
|
* Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
|
||||||
|
|
@ -15770,7 +15770,7 @@ export interface LocatorScreenshotOptions {
|
||||||
* keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenhots of
|
* keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenhots of
|
||||||
* high-dpi devices will be twice as large or even larger. Defaults to `"device"`.
|
* high-dpi devices will be twice as large or even larger. Defaults to `"device"`.
|
||||||
*/
|
*/
|
||||||
size?: "css"|"device";
|
scale?: "css"|"device";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
|
* Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
|
||||||
|
|
@ -15960,7 +15960,7 @@ export interface PageScreenshotOptions {
|
||||||
* keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenhots of
|
* keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenhots of
|
||||||
* high-dpi devices will be twice as large or even larger. Defaults to `"device"`.
|
* high-dpi devices will be twice as large or even larger. Defaults to `"device"`.
|
||||||
*/
|
*/
|
||||||
size?: "css"|"device";
|
scale?: "css"|"device";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
|
* Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
|
||||||
|
|
|
||||||
|
|
@ -311,7 +311,8 @@ export async function toHaveScreenshot(
|
||||||
const screenshotOptions = {
|
const screenshotOptions = {
|
||||||
animations: config?.animations ?? 'disabled',
|
animations: config?.animations ?? 'disabled',
|
||||||
fonts: config?.fonts ?? 'ready',
|
fonts: config?.fonts ?? 'ready',
|
||||||
size: config?.size ?? 'css',
|
scale: config?.scale ?? 'css',
|
||||||
|
caret: config?.caret ?? 'hide',
|
||||||
...helper.allOptions,
|
...helper.allOptions,
|
||||||
mask: (helper.allOptions.mask || []) as LocatorEx[],
|
mask: (helper.allOptions.mask || []) as LocatorEx[],
|
||||||
name: undefined,
|
name: undefined,
|
||||||
|
|
|
||||||
4
packages/playwright-test/types/test.d.ts
vendored
4
packages/playwright-test/types/test.d.ts
vendored
|
|
@ -75,12 +75,12 @@ type ExpectSettings = {
|
||||||
* keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenhots of
|
* keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenhots of
|
||||||
* high-dpi devices will be twice as large or even larger. Defaults to `"css"`.
|
* high-dpi devices will be twice as large or even larger. Defaults to `"css"`.
|
||||||
*/
|
*/
|
||||||
size?: 'css'|'device',
|
scale?: 'css'|'device',
|
||||||
/**
|
/**
|
||||||
* When set to `"hide"`, screenshot will hide text caret.
|
* When set to `"hide"`, screenshot will hide text caret.
|
||||||
* When set to `"initial"`, text caret behavior will not be changed. Defaults to `"hide"`.
|
* When set to `"initial"`, text caret behavior will not be changed. Defaults to `"hide"`.
|
||||||
*/
|
*/
|
||||||
caret?: 'hide'|'initia',
|
caret?: 'hide'|'initial',
|
||||||
}
|
}
|
||||||
toMatchSnapshot?: {
|
toMatchSnapshot?: {
|
||||||
/** An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between pixels in compared images, between zero (strict) and one (lax). Defaults to `0.2`.
|
/** An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between pixels in compared images, between zero (strict) and one (lax). Defaults to `0.2`.
|
||||||
|
|
|
||||||
|
|
@ -90,20 +90,20 @@ browserTest.describe('page screenshot', () => {
|
||||||
await context.close();
|
await context.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
browserTest('should work with device scale factor and size:css', async ({ browser, server }) => {
|
browserTest('should work with device scale factor and scale:css', async ({ browser, server }) => {
|
||||||
const context = await browser.newContext({ viewport: { width: 320, height: 480 }, deviceScaleFactor: 2 });
|
const context = await browser.newContext({ viewport: { width: 320, height: 480 }, deviceScaleFactor: 2 });
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
await page.goto(server.PREFIX + '/grid.html');
|
await page.goto(server.PREFIX + '/grid.html');
|
||||||
const screenshot = await page.screenshot({ size: 'css' });
|
const screenshot = await page.screenshot({ scale: 'css' });
|
||||||
expect(screenshot).toMatchSnapshot('screenshot-device-scale-factor-css-size.png');
|
expect(screenshot).toMatchSnapshot('screenshot-device-scale-factor-css-size.png');
|
||||||
await context.close();
|
await context.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
browserTest('should work with device scale factor, clip and size:css', async ({ browser, server }) => {
|
browserTest('should work with device scale factor, clip and scale:css', async ({ browser, server }) => {
|
||||||
const context = await browser.newContext({ viewport: { width: 500, height: 500 }, deviceScaleFactor: 3 });
|
const context = await browser.newContext({ viewport: { width: 500, height: 500 }, deviceScaleFactor: 3 });
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
await page.goto(server.PREFIX + '/grid.html');
|
await page.goto(server.PREFIX + '/grid.html');
|
||||||
const screenshot = await page.screenshot({ clip: { x: 50, y: 100, width: 150, height: 100 }, size: 'css' });
|
const screenshot = await page.screenshot({ clip: { x: 50, y: 100, width: 150, height: 100 }, scale: 'css' });
|
||||||
expect(screenshot).toMatchSnapshot('screenshot-device-scale-factor-clip-css-size.png');
|
expect(screenshot).toMatchSnapshot('screenshot-device-scale-factor-clip-css-size.png');
|
||||||
await context.close();
|
await context.close();
|
||||||
});
|
});
|
||||||
|
|
@ -396,7 +396,7 @@ browserTest.describe('element screenshot', () => {
|
||||||
await context.close();
|
await context.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
browserTest('should capture full element when larger than viewport with device scale factor and size:css', async ({ browser }) => {
|
browserTest('should capture full element when larger than viewport with device scale factor and scale:css', async ({ browser }) => {
|
||||||
const context = await browser.newContext({ viewport: { width: 501, height: 501 }, deviceScaleFactor: 2.5 });
|
const context = await browser.newContext({ viewport: { width: 501, height: 501 }, deviceScaleFactor: 2.5 });
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
await page.setContent(`
|
await page.setContent(`
|
||||||
|
|
@ -416,7 +416,7 @@ browserTest.describe('element screenshot', () => {
|
||||||
</style>
|
</style>
|
||||||
<div class="to-screenshot"></div>
|
<div class="to-screenshot"></div>
|
||||||
`);
|
`);
|
||||||
const screenshot = await page.locator('div.to-screenshot').screenshot({ size: 'css' });
|
const screenshot = await page.locator('div.to-screenshot').screenshot({ scale: 'css' });
|
||||||
expect(screenshot).toMatchSnapshot('element-larger-than-viewport-dsf-css-size.png');
|
expect(screenshot).toMatchSnapshot('element-larger-than-viewport-dsf-css-size.png');
|
||||||
await context.close();
|
await context.close();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ test('should disable animations by default', async ({ runInlineTest }, testInfo)
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should have size as css by default', async ({ runInlineTest }, testInfo) => {
|
test('should have scale:css by default', async ({ runInlineTest }, testInfo) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
...playwrightConfig({ screenshotsDir: '__screenshots__' }),
|
...playwrightConfig({ screenshotsDir: '__screenshots__' }),
|
||||||
'a.spec.js': `
|
'a.spec.js': `
|
||||||
|
|
@ -339,6 +339,24 @@ test('should generate default name', async ({ runInlineTest }, testInfo) => {
|
||||||
|
|
||||||
test('should compile with different option combinations', async ({ runTSC }) => {
|
test('should compile with different option combinations', async ({ runTSC }) => {
|
||||||
const result = await runTSC({
|
const result = await runTSC({
|
||||||
|
'playwright.config.ts': `
|
||||||
|
import type { PlaywrightTestConfig } from '@playwright/test';
|
||||||
|
const config: PlaywrightTestConfig = {
|
||||||
|
expect: {
|
||||||
|
timeout: 10000,
|
||||||
|
toHaveScreenshot: {
|
||||||
|
threshold: 0.2,
|
||||||
|
maxDiffPixels: 10,
|
||||||
|
maxDiffPixelRatio: 0.2,
|
||||||
|
animations: "allow",
|
||||||
|
fonts: "ready",
|
||||||
|
caret: "hide",
|
||||||
|
scale: "css",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export default config;
|
||||||
|
`,
|
||||||
'a.spec.ts': `
|
'a.spec.ts': `
|
||||||
const { test } = pwt;
|
const { test } = pwt;
|
||||||
test('is a test', async ({ page }) => {
|
test('is a test', async ({ page }) => {
|
||||||
|
|
@ -351,6 +369,9 @@ test('should compile with different option combinations', async ({ runTSC }) =>
|
||||||
maxDiffPixelRatio: 0.2,
|
maxDiffPixelRatio: 0.2,
|
||||||
animations: "disabled",
|
animations: "disabled",
|
||||||
omitBackground: true,
|
omitBackground: true,
|
||||||
|
fonts: "nowait",
|
||||||
|
caret: "initial",
|
||||||
|
scale: "device",
|
||||||
timeout: 1000,
|
timeout: 1000,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
4
utils/generate_types/overrides-test.d.ts
vendored
4
utils/generate_types/overrides-test.d.ts
vendored
|
|
@ -74,12 +74,12 @@ type ExpectSettings = {
|
||||||
* keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenhots of
|
* keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenhots of
|
||||||
* high-dpi devices will be twice as large or even larger. Defaults to `"css"`.
|
* high-dpi devices will be twice as large or even larger. Defaults to `"css"`.
|
||||||
*/
|
*/
|
||||||
size?: 'css'|'device',
|
scale?: 'css'|'device',
|
||||||
/**
|
/**
|
||||||
* When set to `"hide"`, screenshot will hide text caret.
|
* When set to `"hide"`, screenshot will hide text caret.
|
||||||
* When set to `"initial"`, text caret behavior will not be changed. Defaults to `"hide"`.
|
* When set to `"initial"`, text caret behavior will not be changed. Defaults to `"hide"`.
|
||||||
*/
|
*/
|
||||||
caret?: 'hide'|'initia',
|
caret?: 'hide'|'initial',
|
||||||
}
|
}
|
||||||
toMatchSnapshot?: {
|
toMatchSnapshot?: {
|
||||||
/** An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between pixels in compared images, between zero (strict) and one (lax). Defaults to `0.2`.
|
/** An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between pixels in compared images, between zero (strict) and one (lax). Defaults to `0.2`.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue