Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test: canvas updates are reflected on screenshots (#9180)
Yury Semikhatsky6be908d95900
diff --git a/tests/page/page-screenshot.spec.ts b/tests/page/page-screenshot.spec.tsindex 9652c1d058..266fd64468 100644--- a/tests/page/page-screenshot.spec.ts+++ b/tests/page/page-screenshot.spec.ts@@ -171,6 +171,36 @@ it.describe('page screenshot', () => {expect(screenshot).toMatchSnapshot('screenshot-canvas.png', { threshold: 0.4 });});+ it('should capture canvas changes', async ({ page, browserName, isMac }) => {+ it.fail(browserName === 'webkit' && isMac, 'https://github.com/microsoft/playwright/issues/8796');+ 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`);+ }+ });+it('should work for webgl', async ({ page, server, browserName }) => {it.fixme(browserName === 'firefox' || browserName === 'webkit');diff --git a/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-0-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-0-chromium.pngnew file mode 100644index 0000000000..6fcce2cf53Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-0-chromium.png differdiff --git a/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-0-firefox.png b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-0-firefox.pngnew file mode 100644index 0000000000..a5030e8655Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-0-firefox.png differdiff --git a/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-0-webkit.png b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-0-webkit.pngnew file mode 100644index 0000000000..b1515c2b94Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-0-webkit.png differdiff --git a/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-1-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-1-chromium.pngnew file mode 100644index 0000000000..f6f130a44aBinary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-1-chromium.png differdiff --git a/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-1-firefox.png b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-1-firefox.pngnew file mode 100644index 0000000000..0235898c24Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-1-firefox.png differdiff --git a/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-1-webkit.png b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-1-webkit.pngnew file mode 100644index 0000000000..f64458d6abBinary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-1-webkit.png differdiff --git a/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-2-chromium.png b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-2-chromium.pngnew file mode 100644index 0000000000..ecabd8b22dBinary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-2-chromium.png differdiff --git a/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-2-firefox.png b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-2-firefox.pngnew file mode 100644index 0000000000..bb47b0ed4aBinary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-2-firefox.png differdiff --git a/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-2-webkit.png b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-2-webkit.pngnew file mode 100644index 0000000000..ae6f0ec4e0Binary files /dev/null and b/tests/page/page-screenshot.spec.ts-snapshots/canvas-changes-2-webkit.png differ