Skip to content

Commit b89df07

Browse files
authored
test: add device scale factor screenshot tests (#1660)
1 parent 823f961 commit b89df07

File tree

7 files changed

+20
-2
lines changed

7 files changed

+20
-2
lines changed
86.8 KB
Loading
1.5 KB
Loading
107 KB
Loading

test/golden-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function compareImages(actualBuffer, expectedBuffer, mimeType) {
5656
};
5757
}
5858
const diff = new PNG({width: expected.width, height: expected.height});
59-
const count = pixelmatch(expected.data, actual.data, diff.data, expected.width, expected.height, {threshold: 0.1});
59+
const count = pixelmatch(expected.data, actual.data, diff.data, expected.width, expected.height, {threshold: 0.15});
6060
return count > 0 ? { diff: PNG.sync.write(diff) } : null;
6161
}
6262

87 KB
Loading
1.59 KB
Loading

test/screenshot.spec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* @type {PageTestSuite}
2020
*/
21-
module.exports.describe = function({testRunner, expect, product, FFOX, CHROMIUM, WEBKIT}) {
21+
module.exports.describe = function({testRunner, expect, product, playwright, FFOX, CHROMIUM, WEBKIT, LINUX }) {
2222
const {describe, xdescribe, fdescribe} = testRunner;
2323
const {it, fit, xit, dit} = testRunner;
2424
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
@@ -217,6 +217,14 @@ module.exports.describe = function({testRunner, expect, product, FFOX, CHROMIUM,
217217
expect(screenshot).toBeInstanceOf(Buffer);
218218
}
219219
});
220+
it.fail(WEBKIT)('should work with device scale factor', async({browser, server}) => {
221+
const context = await browser.newContext({ viewport: { width: 320, height: 480 }, deviceScaleFactor: 2 });
222+
const page = await context.newPage();
223+
await page.goto(server.PREFIX + '/grid.html');
224+
const screenshot = await page.screenshot();
225+
expect(screenshot).toBeGolden('screenshot-device-scale-factor.png');
226+
await context.close();
227+
});
220228
});
221229

222230
describe('ElementHandle.screenshot', function() {
@@ -386,6 +394,16 @@ module.exports.describe = function({testRunner, expect, product, FFOX, CHROMIUM,
386394
expect(screenshot).toBeGolden('screenshot-element-mobile.png');
387395
await context.close();
388396
});
397+
it.fail(WEBKIT && LINUX).skip(FFOX)('should work with device scale factor', async({browser, server}) => {
398+
const context = await browser.newContext({ viewport: { width: 320, height: 480 }, deviceScaleFactor: 2 });
399+
const page = await context.newPage();
400+
await page.goto(server.PREFIX + '/grid.html');
401+
await page.evaluate(() => window.scrollBy(50, 100));
402+
const elementHandle = await page.$('.box:nth-of-type(3)');
403+
const screenshot = await elementHandle.screenshot();
404+
expect(screenshot).toBeGolden('screenshot-element-mobile-dsf.png');
405+
await context.close();
406+
});
389407
it('should work for an element with an offset', async({page}) => {
390408
await page.setContent('<div style="position:absolute; top: 10.3px; left: 20.4px;width:50.3px;height:20.2px;border:1px solid black;"></div>');
391409
const elementHandle = await page.$('div');

0 commit comments

Comments
 (0)