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: add device scale factor screenshot tests (#1660)
Pavel Feldmanb89df0724738
diff --git a/test/golden-chromium/screenshot-device-scale-factor.png b/test/golden-chromium/screenshot-device-scale-factor.pngnew file mode 100644index 0000000000..1522c3cdd2Binary files /dev/null and b/test/golden-chromium/screenshot-device-scale-factor.png differdiff --git a/test/golden-chromium/screenshot-element-mobile-dsf.png b/test/golden-chromium/screenshot-element-mobile-dsf.pngnew file mode 100644index 0000000000..55a614d1fbBinary files /dev/null and b/test/golden-chromium/screenshot-element-mobile-dsf.png differdiff --git a/test/golden-firefox/screenshot-device-scale-factor.png b/test/golden-firefox/screenshot-device-scale-factor.pngnew file mode 100644index 0000000000..7b9d34c66bBinary files /dev/null and b/test/golden-firefox/screenshot-device-scale-factor.png differdiff --git a/test/golden-utils.js b/test/golden-utils.jsindex 7ae32399d8..71211dbe02 100644--- a/test/golden-utils.js+++ b/test/golden-utils.js@@ -56,7 +56,7 @@ function compareImages(actualBuffer, expectedBuffer, mimeType) {};}const diff = new PNG({width: expected.width, height: expected.height});- const count = pixelmatch(expected.data, actual.data, diff.data, expected.width, expected.height, {threshold: 0.1});+ const count = pixelmatch(expected.data, actual.data, diff.data, expected.width, expected.height, {threshold: 0.15});return count > 0 ? { diff: PNG.sync.write(diff) } : null;}diff --git a/test/golden-webkit/screenshot-device-scale-factor.png b/test/golden-webkit/screenshot-device-scale-factor.pngnew file mode 100644index 0000000000..e02fdc8946Binary files /dev/null and b/test/golden-webkit/screenshot-device-scale-factor.png differdiff --git a/test/golden-webkit/screenshot-element-mobile-dsf.png b/test/golden-webkit/screenshot-element-mobile-dsf.pngnew file mode 100644index 0000000000..8a965e7e64Binary files /dev/null and b/test/golden-webkit/screenshot-element-mobile-dsf.png differdiff --git a/test/screenshot.spec.js b/test/screenshot.spec.jsindex 3ce4b5502c..fba63f0236 100644--- a/test/screenshot.spec.js+++ b/test/screenshot.spec.js@@ -18,7 +18,7 @@/*** @type {PageTestSuite}*/-module.exports.describe = function({testRunner, expect, product, FFOX, CHROMIUM, WEBKIT}) {+module.exports.describe = function({testRunner, expect, product, playwright, FFOX, CHROMIUM, WEBKIT, LINUX }) {const {describe, xdescribe, fdescribe} = testRunner;const {it, fit, xit, dit} = testRunner;const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;@@ -217,6 +217,14 @@ module.exports.describe = function({testRunner, expect, product, FFOX, CHROMIUM,expect(screenshot).toBeInstanceOf(Buffer);}});+ it.fail(WEBKIT)('should work with device scale factor', async({browser, server}) => {+ const context = await browser.newContext({ viewport: { width: 320, height: 480 }, deviceScaleFactor: 2 });+ const page = await context.newPage();+ await page.goto(server.PREFIX + '/grid.html');+ const screenshot = await page.screenshot();+ expect(screenshot).toBeGolden('screenshot-device-scale-factor.png');+ await context.close();+ });});describe('ElementHandle.screenshot', function() {@@ -386,6 +394,16 @@ module.exports.describe = function({testRunner, expect, product, FFOX, CHROMIUM,expect(screenshot).toBeGolden('screenshot-element-mobile.png');await context.close();});+ it.fail(WEBKIT && LINUX).skip(FFOX)('should work with device scale factor', async({browser, server}) => {+ const context = await browser.newContext({ viewport: { width: 320, height: 480 }, deviceScaleFactor: 2 });+ const page = await context.newPage();+ await page.goto(server.PREFIX + '/grid.html');+ await page.evaluate(() => window.scrollBy(50, 100));+ const elementHandle = await page.$('.box:nth-of-type(3)');+ const screenshot = await elementHandle.screenshot();+ expect(screenshot).toBeGolden('screenshot-element-mobile-dsf.png');+ await context.close();+ });it('should work for an element with an offset', async({page}) => {await page.setContent('<div style="position:absolute; top: 10.3px; left: 20.4px;width:50.3px;height:20.2px;border:1px solid black;"></div>');const elementHandle = await page.$('div');