2020-08-04 02:30:37 +03:00
|
|
|
/**
|
|
|
|
* Copyright 2018 Google Inc. All rights reserved.
|
|
|
|
* Modifications copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2020-08-20 07:32:12 +03:00
|
|
|
|
2021-05-06 17:08:22 +03:00
|
|
|
import { test as it, expect } from './pageTest';
|
2022-02-15 18:05:05 +03:00
|
|
|
import { verifyViewport, attachFrame } from '../config/utils';
|
2022-03-16 00:13:45 +03:00
|
|
|
import type { Route } from 'playwright-core';
|
2020-08-18 02:53:19 +03:00
|
|
|
import path from 'path';
|
|
|
|
import fs from 'fs';
|
2022-11-08 02:35:21 +03:00
|
|
|
import { comparePNGs } from '../config/comparator';
|
2020-08-18 02:53:19 +03:00
|
|
|
|
2021-04-05 05:32:14 +03:00
|
|
|
it.describe('page screenshot', () => {
|
2021-05-13 20:22:23 +03:00
|
|
|
it.skip(({ browserName, headless }) => browserName === 'firefox' && !headless, 'Firefox headed produces a different image.');
|
2021-04-30 23:26:13 +03:00
|
|
|
it.skip(({ isAndroid }) => isAndroid, 'Different viewport');
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2022-03-10 21:42:52 +03:00
|
|
|
it('should work @smoke', async ({ page, server }) => {
|
2021-09-27 19:58:08 +03:00
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const screenshot = await page.screenshot();
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(screenshot).toMatchSnapshot('screenshot-sanity.png');
|
2020-08-04 02:30:37 +03:00
|
|
|
});
|
|
|
|
|
2022-07-07 20:21:58 +03:00
|
|
|
it('should not capture blinking caret by default', async ({ page, server, browserName }) => {
|
2022-02-04 08:44:23 +03:00
|
|
|
await page.setContent(`
|
2022-02-18 01:05:56 +03:00
|
|
|
<!-- Refer to stylesheet from other origin. Accessing this
|
|
|
|
stylesheet rules will throw.
|
|
|
|
-->
|
|
|
|
<link rel=stylesheet href="${server.CROSS_PROCESS_PREFIX + '/injectedstyle.css'}">
|
|
|
|
<!-- make life harder: define caret color in stylesheet -->
|
|
|
|
<style>
|
|
|
|
div {
|
|
|
|
caret-color: #000 !important;
|
|
|
|
}
|
|
|
|
</style>
|
2022-02-04 08:44:23 +03:00
|
|
|
<div contenteditable="true"></div>
|
|
|
|
`);
|
|
|
|
const div = page.locator('div');
|
|
|
|
await div.type('foo bar');
|
|
|
|
const screenshot = await div.screenshot();
|
|
|
|
for (let i = 0; i < 10; ++i) {
|
|
|
|
// Caret blinking time is set to 500ms.
|
|
|
|
// Try to capture variety of screenshots to make
|
|
|
|
// sure we don't capture blinking caret.
|
|
|
|
await new Promise(x => setTimeout(x, 150));
|
|
|
|
const newScreenshot = await div.screenshot();
|
|
|
|
expect(newScreenshot.equals(screenshot)).toBe(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-07-07 15:49:40 +03:00
|
|
|
it('should capture blinking caret if explicitly asked for', async ({ page, server, browserName }) => {
|
2023-01-28 08:52:34 +03:00
|
|
|
it.skip(browserName === 'firefox', 'browser-level screenshot API in firefox does not capture caret');
|
|
|
|
|
2022-03-30 03:48:13 +03:00
|
|
|
await page.setContent(`
|
|
|
|
<!-- Refer to stylesheet from other origin. Accessing this
|
|
|
|
stylesheet rules will throw.
|
|
|
|
-->
|
|
|
|
<link rel=stylesheet href="${server.CROSS_PROCESS_PREFIX + '/injectedstyle.css'}">
|
|
|
|
<!-- make life harder: define caret color in stylesheet -->
|
|
|
|
<style>
|
|
|
|
div {
|
|
|
|
caret-color: #000 !important;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<div contenteditable="true"></div>
|
|
|
|
`);
|
|
|
|
const div = page.locator('div');
|
|
|
|
await div.type('foo bar');
|
|
|
|
const screenshot = await div.screenshot();
|
|
|
|
let hasDifferentScreenshots = false;
|
|
|
|
for (let i = 0; !hasDifferentScreenshots && i < 10; ++i) {
|
|
|
|
// Caret blinking time is set to 500ms.
|
|
|
|
// Try to capture variety of screenshots to make
|
|
|
|
// sure we capture blinking caret.
|
|
|
|
await new Promise(x => setTimeout(x, 150));
|
|
|
|
const newScreenshot = await div.screenshot({ caret: 'initial' });
|
|
|
|
hasDifferentScreenshots = !newScreenshot.equals(screenshot);
|
|
|
|
}
|
|
|
|
expect(hasDifferentScreenshots).toBe(true);
|
|
|
|
});
|
|
|
|
|
2022-08-26 22:33:07 +03:00
|
|
|
it('should capture blinking caret in shadow dom', async ({ page, browserName }) => {
|
|
|
|
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/16732' });
|
|
|
|
await page.addScriptTag({
|
|
|
|
content: `
|
|
|
|
class CustomElementContainer extends HTMLElement {
|
|
|
|
#shadowRoot;
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.#shadowRoot = this.attachShadow({ mode: 'open' });
|
|
|
|
this.#shadowRoot.innerHTML = '<custom-element-input-wrapper><input type="text"/></custom-element-input-wrapper>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class CustomElementInputWrapper extends HTMLElement {
|
|
|
|
#shadowRoot;
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.#shadowRoot = this.attachShadow({ mode: 'open' });
|
|
|
|
this.#shadowRoot.innerHTML = '<style>:host { all: initial; }</style><slot/>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
customElements.define('custom-element-input-wrapper', CustomElementInputWrapper);
|
|
|
|
customElements.define('custom-element-container', CustomElementContainer);
|
|
|
|
|
|
|
|
const container = document.createElement('custom-element-container');
|
|
|
|
document.body.appendChild(container);`,
|
|
|
|
});
|
|
|
|
|
|
|
|
const input = await page.locator('input');
|
|
|
|
// TODO: click fails in webkit
|
|
|
|
await input.focus();
|
|
|
|
|
|
|
|
const screenshot = await input.screenshot();
|
|
|
|
let hasDifferentScreenshots = false;
|
|
|
|
for (let i = 0; !hasDifferentScreenshots && i < 10; ++i) {
|
|
|
|
// Caret blinking time is set to 500ms.
|
|
|
|
// Try to capture variety of screenshots to make
|
|
|
|
// sure we capture blinking caret.
|
|
|
|
await new Promise(x => setTimeout(x, 150));
|
|
|
|
const newScreenshot = await input.screenshot({ caret: 'hide' });
|
|
|
|
hasDifferentScreenshots = !newScreenshot.equals(screenshot);
|
|
|
|
}
|
|
|
|
expect(hasDifferentScreenshots).toBe(false);
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should clip rect', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const screenshot = await page.screenshot({
|
|
|
|
clip: {
|
|
|
|
x: 50,
|
|
|
|
y: 100,
|
|
|
|
width: 150,
|
|
|
|
height: 100
|
|
|
|
}
|
|
|
|
});
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(screenshot).toMatchSnapshot('screenshot-clip-rect.png');
|
2020-08-04 02:30:37 +03:00
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should clip rect with fullPage', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
await page.evaluate(() => window.scrollBy(150, 200));
|
|
|
|
const screenshot = await page.screenshot({
|
|
|
|
fullPage: true,
|
|
|
|
clip: {
|
|
|
|
x: 50,
|
|
|
|
y: 100,
|
|
|
|
width: 150,
|
|
|
|
height: 100,
|
|
|
|
},
|
|
|
|
});
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(screenshot).toMatchSnapshot('screenshot-clip-rect.png');
|
2020-08-04 02:30:37 +03:00
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should clip elements to the viewport', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const screenshot = await page.screenshot({
|
|
|
|
clip: {
|
|
|
|
x: 50,
|
|
|
|
y: 450,
|
|
|
|
width: 1000,
|
|
|
|
height: 100
|
|
|
|
}
|
|
|
|
});
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(screenshot).toMatchSnapshot('screenshot-offscreen-clip.png');
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should throw on clip outside the viewport', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const screenshotError = await page.screenshot({
|
2020-08-04 02:30:37 +03:00
|
|
|
clip: {
|
2020-08-28 23:53:47 +03:00
|
|
|
x: 50,
|
|
|
|
y: 650,
|
|
|
|
width: 100,
|
|
|
|
height: 100
|
2020-08-04 02:30:37 +03:00
|
|
|
}
|
2020-08-28 23:53:47 +03:00
|
|
|
}).catch(error => error);
|
|
|
|
expect(screenshotError.message).toContain('Clipped area is either empty or outside the resulting image');
|
|
|
|
});
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should run in parallel', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const promises = [];
|
|
|
|
for (let i = 0; i < 3; ++i) {
|
|
|
|
promises.push(page.screenshot({
|
|
|
|
clip: {
|
|
|
|
x: 50 * i,
|
|
|
|
y: 0,
|
|
|
|
width: 50,
|
|
|
|
height: 50
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
const screenshots = await Promise.all(promises);
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(screenshots[1]).toMatchSnapshot('grid-cell-1.png');
|
2020-08-04 02:30:37 +03:00
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should take fullPage screenshots', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const screenshot = await page.screenshot({
|
|
|
|
fullPage: true
|
|
|
|
});
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(screenshot).toMatchSnapshot('screenshot-grid-fullpage.png');
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should restore viewport after fullPage screenshot', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-04 02:30:37 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
2020-08-28 23:53:47 +03:00
|
|
|
const screenshot = await page.screenshot({ fullPage: true });
|
|
|
|
expect(screenshot).toBeInstanceOf(Buffer);
|
2020-09-19 01:52:14 +03:00
|
|
|
await verifyViewport(page, 500, 500);
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2023-01-06 00:51:08 +03:00
|
|
|
it('should allow transparency', async ({ page, browserName }) => {
|
2021-04-05 05:32:14 +03:00
|
|
|
it.fail(browserName === 'firefox');
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.setViewportSize({ width: 50, height: 150 });
|
|
|
|
await page.setContent(`
|
|
|
|
<style>
|
|
|
|
body { margin: 0 }
|
|
|
|
div { width: 50px; height: 50px; }
|
|
|
|
</style>
|
|
|
|
<div style="background:black"></div>
|
|
|
|
<div style="background:white"></div>
|
|
|
|
<div style="background:transparent"></div>
|
|
|
|
`);
|
2021-09-27 19:58:08 +03:00
|
|
|
const screenshot = await page.screenshot({ omitBackground: true });
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(screenshot).toMatchSnapshot('transparent.png');
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should render white background on jpeg file', async ({ page, server, isElectron }) => {
|
2021-04-09 17:59:09 +03:00
|
|
|
it.fixme(isElectron, 'omitBackground with jpeg does not work');
|
2021-04-08 20:26:26 +03:00
|
|
|
|
2022-06-09 01:13:39 +03:00
|
|
|
await page.setViewportSize({ width: 300, height: 300 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2021-09-27 19:58:08 +03:00
|
|
|
const screenshot = await page.screenshot({ omitBackground: true, type: 'jpeg' });
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(screenshot).toMatchSnapshot('white.jpg');
|
2020-08-04 02:30:37 +03:00
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should work with odd clip size on Retina displays', async ({ page, isElectron }) => {
|
2021-05-11 16:40:06 +03:00
|
|
|
it.fixme(isElectron, 'Scale is wrong');
|
|
|
|
|
2020-08-28 23:53:47 +03:00
|
|
|
const screenshot = await page.screenshot({
|
|
|
|
clip: {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 11,
|
|
|
|
height: 11,
|
|
|
|
}
|
|
|
|
});
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(screenshot).toMatchSnapshot('screenshot-clip-odd-size.png');
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2023-02-10 21:54:00 +03:00
|
|
|
it('should work for canvas', async ({ page, server, browserName, channel, browserMajorVersion, isElectron, isMac }) => {
|
2023-02-02 18:14:18 +03:00
|
|
|
it.fixme(browserName === 'firefox' && channel === 'firefox-beta' && browserMajorVersion === 110, 'https://github.com/microsoft/playwright/issues/20522');
|
2023-02-10 21:54:00 +03:00
|
|
|
it.fixme(isElectron && isMac, 'Fails on the bots');
|
2021-09-27 19:58:08 +03:00
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/screenshots/canvas.html');
|
|
|
|
const screenshot = await page.screenshot();
|
2022-12-30 10:48:28 +03:00
|
|
|
expect(screenshot).toMatchSnapshot('screenshot-canvas.png');
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2022-09-07 21:09:22 +03:00
|
|
|
it('should capture canvas changes', async ({ page, isElectron, browserName, isMac, isWebView2 }) => {
|
2022-08-04 00:51:11 +03:00
|
|
|
it.fixme(browserName === 'webkit' && isMac, 'https://github.com/microsoft/playwright/issues/8796,https://github.com/microsoft/playwright/issues/16180');
|
2021-10-02 05:40:47 +03:00
|
|
|
it.skip(isElectron);
|
2022-09-07 21:09:22 +03:00
|
|
|
it.skip(isWebView2);
|
2021-09-27 23:45:03 +03:00
|
|
|
await page.goto('data:text/html,<canvas></canvas>');
|
|
|
|
await page.evaluate(() => {
|
|
|
|
const canvas = document.querySelector('canvas');
|
|
|
|
canvas.width = 600;
|
|
|
|
canvas.height = 600;
|
|
|
|
});
|
|
|
|
|
|
|
|
async function addLine(step: number) {
|
|
|
|
await page.evaluate(n => {
|
|
|
|
const canvas = document.querySelector('canvas');
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
ctx.lineWidth = 1;
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(0, n * 100);
|
|
|
|
ctx.lineTo(300, n * 100);
|
|
|
|
ctx.stroke();
|
|
|
|
}, step);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
|
await addLine(i);
|
|
|
|
// With the slight delay WebKit stops reflecting changes in the screenshots on macOS.
|
|
|
|
await new Promise(f => setTimeout(f, 100));
|
|
|
|
const screenshot = await page.screenshot();
|
|
|
|
expect(screenshot).toMatchSnapshot(`canvas-changes-${i}.png`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should work for webgl', async ({ page, server, browserName }) => {
|
2023-01-28 08:52:34 +03:00
|
|
|
it.fixme(browserName === 'firefox');
|
2021-04-05 05:32:14 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
await page.setViewportSize({ width: 640, height: 480 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/screenshots/webgl.html');
|
|
|
|
const screenshot = await page.screenshot();
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(screenshot).toMatchSnapshot('screenshot-webgl.png');
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should work for translateZ', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/screenshots/translateZ.html');
|
|
|
|
const screenshot = await page.screenshot();
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(screenshot).toMatchSnapshot('screenshot-translateZ.png');
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should work while navigating', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/redirectloop1.html');
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
|
const screenshot = await page.screenshot({ fullPage: true }).catch(e => {
|
|
|
|
if (e.message.includes('Cannot take a screenshot while page is navigating'))
|
|
|
|
return Buffer.from('');
|
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
expect(screenshot).toBeInstanceOf(Buffer);
|
|
|
|
}
|
|
|
|
});
|
2020-08-04 02:30:37 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should work with iframe in shadow', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid-iframe-in-shadow.html');
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(await page.screenshot()).toMatchSnapshot('screenshot-iframe.png');
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
2020-08-18 02:53:19 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('path option should work', async ({ page, server }, testInfo) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
2020-10-06 03:03:24 +03:00
|
|
|
const outputPath = testInfo.outputPath('screenshot.png');
|
2021-09-27 19:58:08 +03:00
|
|
|
await page.screenshot({ path: outputPath });
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(await fs.promises.readFile(outputPath)).toMatchSnapshot('screenshot-sanity.png');
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
2020-08-19 04:46:56 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('path option should create subdirectories', async ({ page, server }, testInfo) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
2020-10-06 03:03:24 +03:00
|
|
|
const outputPath = testInfo.outputPath(path.join('these', 'are', 'directories', 'screenshot.png'));
|
2021-09-27 19:58:08 +03:00
|
|
|
await page.screenshot({ path: outputPath });
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(await fs.promises.readFile(outputPath)).toMatchSnapshot('screenshot-sanity.png');
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
2020-08-19 04:46:56 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('path option should detect jpeg', async ({ page, server, isElectron }, testInfo) => {
|
2021-04-09 17:59:09 +03:00
|
|
|
it.fixme(isElectron, 'omitBackground with jpeg does not work');
|
2021-04-08 20:26:26 +03:00
|
|
|
|
2022-06-09 01:13:39 +03:00
|
|
|
await page.setViewportSize({ width: 300, height: 300 });
|
2020-08-28 23:53:47 +03:00
|
|
|
await page.goto(server.EMPTY_PAGE);
|
2020-10-06 03:03:24 +03:00
|
|
|
const outputPath = testInfo.outputPath('screenshot.jpg');
|
2021-09-27 19:58:08 +03:00
|
|
|
const screenshot = await page.screenshot({ omitBackground: true, path: outputPath });
|
2020-10-07 01:51:18 +03:00
|
|
|
expect(await fs.promises.readFile(outputPath)).toMatchSnapshot('white.jpg');
|
|
|
|
expect(screenshot).toMatchSnapshot('white.jpg');
|
2020-08-28 23:53:47 +03:00
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('path option should throw for unsupported mime type', async ({ page }) => {
|
2020-08-28 23:53:47 +03:00
|
|
|
const error = await page.screenshot({ path: 'file.txt' }).catch(e => e);
|
|
|
|
expect(error.message).toContain('path: unsupported mime type "text/plain"');
|
|
|
|
});
|
2020-10-11 07:50:37 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('quality option should throw for png', async ({ page }) => {
|
2020-12-23 20:53:14 +03:00
|
|
|
const error = await page.screenshot({ quality: 10 }).catch(e => e);
|
|
|
|
expect(error.message).toContain('options.quality is unsupported for the png');
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('zero quality option should throw for png', async ({ page }) => {
|
2020-12-23 20:53:14 +03:00
|
|
|
const error = await page.screenshot({ quality: 0, type: 'png' }).catch(e => e);
|
|
|
|
expect(error.message).toContain('options.quality is unsupported for the png');
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should prefer type over extension', async ({ page }, testInfo) => {
|
2020-11-03 00:38:55 +03:00
|
|
|
const outputPath = testInfo.outputPath('file.png');
|
|
|
|
const buffer = await page.screenshot({ path: outputPath, type: 'jpeg' });
|
2020-10-27 10:02:35 +03:00
|
|
|
expect([buffer[0], buffer[1], buffer[2]]).toEqual([0xFF, 0xD8, 0xFF]);
|
|
|
|
});
|
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should not issue resize event', async ({ page, server }) => {
|
2021-04-05 05:32:14 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
let resizeTriggered = false;
|
|
|
|
await page.exposeFunction('resize', () => {
|
|
|
|
resizeTriggered = true;
|
|
|
|
});
|
|
|
|
await page.evaluate(() => {
|
|
|
|
window.addEventListener('resize', () => (window as any).resize());
|
|
|
|
});
|
|
|
|
await page.screenshot();
|
|
|
|
expect(resizeTriggered).toBeFalsy();
|
|
|
|
});
|
2021-04-30 00:53:53 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should work with Array deleted', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2021-04-30 00:53:53 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
await page.evaluate(() => delete window.Array);
|
|
|
|
const screenshot = await page.screenshot({ fullPage: true });
|
|
|
|
expect(screenshot).toMatchSnapshot('screenshot-grid-fullpage.png');
|
|
|
|
});
|
2021-04-07 02:01:38 +03:00
|
|
|
|
2021-09-27 19:58:08 +03:00
|
|
|
it('should take fullPage screenshots during navigation', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
2021-04-07 02:01:38 +03:00
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const reloadSeveralTimes = async () => {
|
|
|
|
for (let i = 0; i < 5; ++i)
|
|
|
|
await page.reload();
|
|
|
|
};
|
|
|
|
const screenshotSeveralTimes = async () => {
|
|
|
|
for (let i = 0; i < 5; ++i)
|
|
|
|
await page.screenshot({ fullPage: true });
|
|
|
|
};
|
|
|
|
await Promise.all([
|
|
|
|
reloadSeveralTimes(),
|
|
|
|
screenshotSeveralTimes()
|
|
|
|
]);
|
|
|
|
});
|
2022-02-15 18:05:05 +03:00
|
|
|
|
|
|
|
it.describe('mask option', () => {
|
|
|
|
it('should work', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
expect(await page.screenshot({
|
2022-08-18 21:12:33 +03:00
|
|
|
mask: [page.locator('div').nth(5)],
|
2022-02-15 18:05:05 +03:00
|
|
|
})).toMatchSnapshot('mask-should-work.png');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work with locator', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const bodyLocator = page.locator('body');
|
|
|
|
expect(await bodyLocator.screenshot({
|
2022-08-18 21:12:33 +03:00
|
|
|
mask: [page.locator('div').nth(5)],
|
2022-02-15 18:05:05 +03:00
|
|
|
})).toMatchSnapshot('mask-should-work-with-locator.png');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work with elementhandle', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const bodyHandle = await page.$('body');
|
|
|
|
expect(await bodyHandle.screenshot({
|
2022-08-18 21:12:33 +03:00
|
|
|
mask: [page.locator('div').nth(5)],
|
2022-02-15 18:05:05 +03:00
|
|
|
})).toMatchSnapshot('mask-should-work-with-elementhandle.png');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should mask multiple elements', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
expect(await page.screenshot({
|
|
|
|
mask: [
|
|
|
|
page.locator('div').nth(5),
|
|
|
|
page.locator('div').nth(12),
|
|
|
|
],
|
|
|
|
})).toMatchSnapshot('should-mask-multiple-elements.png');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should mask inside iframe', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
await attachFrame(page, 'frame1', server.PREFIX + '/grid.html');
|
|
|
|
await page.addStyleTag({ content: 'iframe { border: none; }' });
|
|
|
|
expect(await page.screenshot({
|
|
|
|
mask: [
|
|
|
|
page.locator('div').nth(5),
|
|
|
|
page.frameLocator('#frame1').locator('div').nth(12),
|
|
|
|
],
|
|
|
|
})).toMatchSnapshot('should-mask-inside-iframe.png');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should mask in parallel', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
|
|
|
await attachFrame(page, 'frame1', server.PREFIX + '/grid.html');
|
|
|
|
await attachFrame(page, 'frame2', server.PREFIX + '/grid.html');
|
|
|
|
await page.addStyleTag({ content: 'iframe { border: none; }' });
|
|
|
|
const screenshots = await Promise.all([
|
|
|
|
page.screenshot({
|
2022-08-18 21:12:33 +03:00
|
|
|
mask: [page.frameLocator('#frame1').locator('div').nth(1)],
|
2022-02-15 18:05:05 +03:00
|
|
|
}),
|
|
|
|
page.screenshot({
|
2022-08-18 21:12:33 +03:00
|
|
|
mask: [page.frameLocator('#frame2').locator('div').nth(3)],
|
2022-02-15 18:05:05 +03:00
|
|
|
}),
|
|
|
|
]);
|
|
|
|
expect(screenshots[0]).toMatchSnapshot('should-mask-in-parallel-1.png');
|
|
|
|
expect(screenshots[1]).toMatchSnapshot('should-mask-in-parallel-2.png');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove mask after screenshot', async ({ page, server }) => {
|
|
|
|
await page.setViewportSize({ width: 500, height: 500 });
|
|
|
|
await page.goto(server.PREFIX + '/grid.html');
|
|
|
|
const screenshot1 = await page.screenshot();
|
|
|
|
await page.screenshot({
|
2022-08-18 21:12:33 +03:00
|
|
|
mask: [page.locator('div').nth(1)],
|
2022-02-15 18:05:05 +03:00
|
|
|
});
|
|
|
|
const screenshot2 = await page.screenshot();
|
|
|
|
expect(screenshot1.equals(screenshot2)).toBe(true);
|
|
|
|
});
|
2022-03-16 00:13:45 +03:00
|
|
|
|
|
|
|
it('should work when subframe has stalled navigation', async ({ page, server }) => {
|
|
|
|
let cb;
|
|
|
|
const routeReady = new Promise<Route>(f => cb = f);
|
|
|
|
await page.route('**/subframe.html', cb); // Stalling subframe.
|
|
|
|
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
const done = page.setContent(`<iframe src='/subframe.html'></iframe>`);
|
|
|
|
const route = await routeReady;
|
|
|
|
|
2022-08-18 21:12:33 +03:00
|
|
|
await page.screenshot({ mask: [page.locator('non-existent')] });
|
2022-03-16 00:13:45 +03:00
|
|
|
await route.fulfill({ body: '' });
|
|
|
|
await done;
|
|
|
|
});
|
2022-04-01 01:33:29 +03:00
|
|
|
|
|
|
|
it('should work when subframe used document.open after a weird url', async ({ page, server }) => {
|
|
|
|
await page.goto(server.EMPTY_PAGE);
|
|
|
|
await page.evaluate(() => {
|
|
|
|
const iframe = document.createElement('iframe');
|
|
|
|
iframe.src = 'javascript:hi';
|
|
|
|
document.body.appendChild(iframe);
|
|
|
|
iframe.contentDocument.open();
|
|
|
|
iframe.contentDocument.write('Hello');
|
|
|
|
iframe.contentDocument.close();
|
|
|
|
});
|
2022-08-18 21:12:33 +03:00
|
|
|
await page.screenshot({ mask: [page.locator('non-existent')] });
|
2022-04-01 01:33:29 +03:00
|
|
|
});
|
2022-02-15 18:05:05 +03:00
|
|
|
});
|
2020-08-19 04:46:56 +03:00
|
|
|
});
|
2022-02-09 23:52:11 +03:00
|
|
|
|
|
|
|
async function rafraf(page) {
|
|
|
|
// Do a double raf since single raf does not
|
|
|
|
// actually guarantee a new animation frame.
|
|
|
|
await page.evaluate(() => new Promise(x => {
|
|
|
|
requestAnimationFrame(() => requestAnimationFrame(x));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
declare global {
|
|
|
|
interface Window {
|
|
|
|
animation?: Animation;
|
|
|
|
_EVENTS?: string[];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
it.describe('page screenshot animations', () => {
|
|
|
|
it('should not capture infinite css animation', async ({ page, server }) => {
|
|
|
|
await page.goto(server.PREFIX + '/rotate-z.html');
|
|
|
|
const div = page.locator('div');
|
|
|
|
const screenshot = await div.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
for (let i = 0; i < 10; ++i) {
|
|
|
|
await rafraf(page);
|
|
|
|
const newScreenshot = await div.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
expect(newScreenshot.equals(screenshot)).toBe(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not capture pseudo element css animation', async ({ page, server }) => {
|
|
|
|
await page.goto(server.PREFIX + '/rotate-pseudo.html');
|
|
|
|
const div = page.locator('div');
|
|
|
|
const screenshot = await div.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
for (let i = 0; i < 10; ++i) {
|
|
|
|
await rafraf(page);
|
|
|
|
const newScreenshot = await div.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
expect(newScreenshot.equals(screenshot)).toBe(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-03-10 20:46:50 +03:00
|
|
|
it('should not capture css animations in shadow DOM', async ({ page, server, isAndroid }) => {
|
|
|
|
it.skip(isAndroid, 'Different viewport');
|
2022-02-09 23:52:11 +03:00
|
|
|
await page.goto(server.PREFIX + '/rotate-z-shadow-dom.html');
|
|
|
|
const screenshot = await page.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
for (let i = 0; i < 4; ++i) {
|
|
|
|
await rafraf(page);
|
|
|
|
const newScreenshot = await page.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
expect(newScreenshot.equals(screenshot)).toBe(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-03-10 20:46:50 +03:00
|
|
|
it('should stop animations that happen right before screenshot', async ({ page, server, mode, isAndroid }) => {
|
2022-02-09 23:52:11 +03:00
|
|
|
it.skip(mode !== 'default');
|
2022-03-10 20:46:50 +03:00
|
|
|
it.skip(isAndroid, 'Different viewport');
|
2022-02-09 23:52:11 +03:00
|
|
|
await page.goto(server.PREFIX + '/rotate-z.html');
|
|
|
|
// Stop rotating bar.
|
|
|
|
await page.$eval('div', el => el.style.setProperty('animation', 'none'));
|
|
|
|
const buffer1 = await page.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
// Start rotating bar right before screenshot.
|
|
|
|
__testHookBeforeScreenshot: async () => {
|
|
|
|
await page.$eval('div', el => el.style.removeProperty('animation'));
|
|
|
|
},
|
|
|
|
} as any);
|
|
|
|
await rafraf(page);
|
|
|
|
const buffer2 = await page.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
2022-11-08 02:35:21 +03:00
|
|
|
expect(comparePNGs(buffer1, buffer2)).toBe(null);
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should resume infinite animations', async ({ page, server }) => {
|
|
|
|
await page.goto(server.PREFIX + '/rotate-z.html');
|
|
|
|
await page.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
const buffer1 = await page.screenshot();
|
|
|
|
await rafraf(page);
|
|
|
|
const buffer2 = await page.screenshot();
|
2022-12-30 10:48:28 +03:00
|
|
|
expect(comparePNGs(buffer1, buffer2, { maxDiffPixels: 50 })).not.toBe(null);
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not capture infinite web animations', async ({ page, server }) => {
|
|
|
|
await page.goto(server.PREFIX + '/web-animation.html');
|
|
|
|
const div = page.locator('div');
|
|
|
|
const screenshot = await div.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
for (let i = 0; i < 10; ++i) {
|
|
|
|
await rafraf(page);
|
|
|
|
const newScreenshot = await div.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
expect(newScreenshot.equals(screenshot)).toBe(true);
|
|
|
|
}
|
|
|
|
// Should resume infinite web animation.
|
|
|
|
const buffer1 = await page.screenshot();
|
|
|
|
await rafraf(page);
|
|
|
|
const buffer2 = await page.screenshot();
|
2022-12-30 10:48:28 +03:00
|
|
|
expect(comparePNGs(buffer1, buffer2, { maxDiffPixels: 50 })).not.toBe(null);
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should fire transitionend for finite transitions', async ({ page, server }) => {
|
|
|
|
await page.goto(server.PREFIX + '/css-transition.html');
|
|
|
|
const div = page.locator('div');
|
|
|
|
await div.evaluate(el => {
|
|
|
|
el.addEventListener('transitionend', () => window['__TRANSITION_END'] = true, false);
|
|
|
|
});
|
|
|
|
|
|
|
|
await it.step('make sure transition is actually running', async () => {
|
|
|
|
const screenshot1 = await page.screenshot();
|
|
|
|
await rafraf(page);
|
|
|
|
const screenshot2 = await page.screenshot();
|
|
|
|
expect(screenshot1.equals(screenshot2)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Make a screenshot that finishes all finite animations.
|
|
|
|
const screenshot1 = await div.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
await rafraf(page);
|
|
|
|
// Make sure finite transition is not restarted.
|
2022-03-11 04:15:36 +03:00
|
|
|
const screenshot2 = await div.screenshot({ animations: 'allow' });
|
2022-02-09 23:52:11 +03:00
|
|
|
expect(screenshot1.equals(screenshot2)).toBe(true);
|
|
|
|
|
|
|
|
expect(await page.evaluate(() => window['__TRANSITION_END'])).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should capture screenshots after layoutchanges in transitionend event', async ({ page, server }) => {
|
|
|
|
await page.goto(server.PREFIX + '/css-transition.html');
|
|
|
|
const div = page.locator('div');
|
|
|
|
await div.evaluate(el => {
|
|
|
|
el.addEventListener('transitionend', () => {
|
|
|
|
const time = Date.now();
|
|
|
|
// Block main thread for 200ms, emulating heavy layout.
|
|
|
|
while (Date.now() - time < 200) ;
|
|
|
|
const h1 = document.createElement('h1');
|
|
|
|
h1.textContent = 'woof-woof';
|
|
|
|
document.body.append(h1);
|
|
|
|
}, false);
|
|
|
|
});
|
|
|
|
|
|
|
|
await it.step('make sure transition is actually running', async () => {
|
|
|
|
const screenshot1 = await page.screenshot();
|
|
|
|
await rafraf(page);
|
|
|
|
const screenshot2 = await page.screenshot();
|
|
|
|
expect(screenshot1.equals(screenshot2)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
// 1. Make a screenshot that finishes all finite animations
|
|
|
|
// and triggers layout.
|
|
|
|
const screenshot1 = await page.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// 2. Make a second screenshot after h1 is on screen.
|
|
|
|
await expect(page.locator('h1')).toBeVisible();
|
|
|
|
await expect(page.locator('h1')).toHaveText('woof-woof');
|
|
|
|
const screenshot2 = await page.screenshot();
|
|
|
|
|
|
|
|
// 3. Make sure both screenshots are equal, meaning that
|
|
|
|
// first screenshot actually was taken after transitionend
|
|
|
|
// changed layout.
|
|
|
|
expect(screenshot1.equals(screenshot2)).toBe(true);
|
|
|
|
});
|
|
|
|
|
2022-03-10 20:46:50 +03:00
|
|
|
it('should not change animation with playbackRate equal to 0', async ({ page, server, isAndroid }) => {
|
|
|
|
it.skip(isAndroid, 'Different viewport');
|
2022-02-09 23:52:11 +03:00
|
|
|
await page.goto(server.PREFIX + '/rotate-z.html');
|
|
|
|
await page.evaluate(async () => {
|
|
|
|
window.animation = document.getAnimations()[0];
|
2022-02-15 18:05:05 +03:00
|
|
|
await window.animation.ready;
|
2022-02-09 23:52:11 +03:00
|
|
|
window.animation.updatePlaybackRate(0);
|
|
|
|
await window.animation.ready;
|
|
|
|
window.animation.currentTime = 500;
|
|
|
|
});
|
|
|
|
const screenshot1 = await page.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
await rafraf(page);
|
|
|
|
const screenshot2 = await page.screenshot({
|
2022-03-04 22:02:59 +03:00
|
|
|
animations: 'disabled',
|
2022-02-09 23:52:11 +03:00
|
|
|
});
|
|
|
|
expect(screenshot1.equals(screenshot2)).toBe(true);
|
|
|
|
expect(await page.evaluate(() => ({
|
|
|
|
playbackRate: window.animation.playbackRate,
|
|
|
|
currentTime: window.animation.currentTime,
|
|
|
|
}))).toEqual({
|
|
|
|
playbackRate: 0,
|
|
|
|
currentTime: 500,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should trigger particular events for css transitions', async ({ page, server }) => {
|
|
|
|
await page.goto(server.PREFIX + '/css-transition.html');
|
|
|
|
const div = page.locator('div');
|
|
|
|
await div.evaluate(async el => {
|
|
|
|
window._EVENTS = [];
|
|
|
|
el.addEventListener('transitionend', () => {
|
|
|
|
window._EVENTS.push('transitionend');
|
|
|
|
console.log('transitionend');
|
|
|
|
}, false);
|
|
|
|
const animation = el.getAnimations()[0];
|
|
|
|
animation.oncancel = () => window._EVENTS.push('oncancel');
|
|
|
|
animation.onfinish = () => window._EVENTS.push('onfinish');
|
|
|
|
animation.onremove = () => window._EVENTS.push('onremove');
|
|
|
|
await animation.ready;
|
|
|
|
});
|
|
|
|
await Promise.all([
|
2022-03-04 22:02:59 +03:00
|
|
|
page.screenshot({ animations: 'disabled' }),
|
2022-02-09 23:52:11 +03:00
|
|
|
page.waitForEvent('console', msg => msg.text() === 'transitionend'),
|
|
|
|
]);
|
|
|
|
expect(await page.evaluate(() => window._EVENTS)).toEqual([
|
|
|
|
'onfinish', 'transitionend'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should trigger particular events for INfinite css animation', async ({ page, server }) => {
|
|
|
|
await page.goto(server.PREFIX + '/rotate-z.html');
|
|
|
|
const div = page.locator('div');
|
|
|
|
await div.evaluate(async el => {
|
|
|
|
window._EVENTS = [];
|
|
|
|
el.addEventListener('animationcancel', () => {
|
|
|
|
window._EVENTS.push('animationcancel');
|
|
|
|
console.log('animationcancel');
|
|
|
|
}, false);
|
|
|
|
const animation = el.getAnimations()[0];
|
|
|
|
animation.oncancel = () => window._EVENTS.push('oncancel');
|
|
|
|
animation.onfinish = () => window._EVENTS.push('onfinish');
|
|
|
|
animation.onremove = () => window._EVENTS.push('onremove');
|
|
|
|
await animation.ready;
|
|
|
|
});
|
|
|
|
await Promise.all([
|
2022-03-04 22:02:59 +03:00
|
|
|
page.screenshot({ animations: 'disabled' }),
|
2022-02-09 23:52:11 +03:00
|
|
|
page.waitForEvent('console', msg => msg.text() === 'animationcancel'),
|
|
|
|
]);
|
|
|
|
expect(await page.evaluate(() => window._EVENTS)).toEqual([
|
|
|
|
'oncancel', 'animationcancel'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should trigger particular events for finite css animation', async ({ page, server }) => {
|
|
|
|
await page.goto(server.PREFIX + '/rotate-z.html');
|
|
|
|
const div = page.locator('div');
|
|
|
|
await div.evaluate(async el => {
|
|
|
|
window._EVENTS = [];
|
|
|
|
// Make CSS animation to be finite.
|
|
|
|
el.style.setProperty('animation-iteration-count', '1000');
|
|
|
|
el.addEventListener('animationend', () => {
|
|
|
|
window._EVENTS.push('animationend');
|
|
|
|
console.log('animationend');
|
|
|
|
}, false);
|
|
|
|
const animation = el.getAnimations()[0];
|
|
|
|
animation.oncancel = () => window._EVENTS.push('oncancel');
|
|
|
|
animation.onfinish = () => window._EVENTS.push('onfinish');
|
|
|
|
animation.onremove = () => window._EVENTS.push('onremove');
|
|
|
|
await animation.ready;
|
|
|
|
});
|
|
|
|
// Ensure CSS animation is finite.
|
|
|
|
expect(await div.evaluate(async el => Number.isFinite(el.getAnimations()[0].effect.getComputedTiming().endTime))).toBe(true);
|
|
|
|
await Promise.all([
|
2022-03-04 22:02:59 +03:00
|
|
|
page.screenshot({ animations: 'disabled' }),
|
2022-02-09 23:52:11 +03:00
|
|
|
page.waitForEvent('console', msg => msg.text() === 'animationend'),
|
|
|
|
]);
|
|
|
|
expect(await page.evaluate(() => window._EVENTS)).toEqual([
|
|
|
|
'onfinish', 'animationend'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2022-02-15 18:05:05 +03:00
|
|
|
|
2022-09-02 04:15:49 +03:00
|
|
|
it('should throw if screenshot size is too large', async ({ page, browserName, isMac }) => {
|
|
|
|
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/16727' });
|
|
|
|
{
|
|
|
|
await page.setContent(`<style>body {margin: 0; padding: 0;}</style><div style='min-height: 32767px; background: red;'></div>`);
|
|
|
|
const result = await page.screenshot({ fullPage: true });
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
await page.setContent(`<style>body {margin: 0; padding: 0;}</style><div style='min-height: 32768px; background: red;'></div>`);
|
|
|
|
const exception = await page.screenshot({ fullPage: true }).catch(e => e);
|
|
|
|
if (browserName === 'firefox' || (browserName === 'webkit' && !isMac))
|
|
|
|
expect(exception.message).toContain('Cannot take screenshot larger than 32767');
|
|
|
|
}
|
|
|
|
});
|