Skip to content

Commit 2c92f48

Browse files
committed
Update comparison script
1 parent 40165c1 commit 2c92f48

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

maestro/helpers/compare_screenshots.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ function isIgnored(x, y, ignoredAreas) {
2222
);
2323
}
2424

25+
function applyIgnoredAreas(img, ignoredAreas) {
26+
const { width, height } = img;
27+
for (let y = 0; y < height; y++) {
28+
for (let x = 0; x < width; x++) {
29+
if (isIgnored(x, y, ignoredAreas)) {
30+
const idx = (width * y + x) << 2;
31+
img.data[idx] = 0; // R
32+
img.data[idx + 1] = 0; // G
33+
img.data[idx + 2] = 0; // B
34+
img.data[idx + 3] = 0; // A (transparent)
35+
}
36+
}
37+
}
38+
}
39+
2540
const failedComparisons = [];
2641

2742
fs.readdirSync(actualDir).forEach(file => {
@@ -40,13 +55,20 @@ fs.readdirSync(actualDir).forEach(file => {
4055
ignoredAreas = [
4156
{ x: 0, y: height - 40, width, height: 40 } // Ignore bottom 40 pixels where is Home Indicator on iOS
4257
];
58+
} else if (platform === 'android') {
59+
ignoredAreas = [
60+
{ x: 0, y: 0, width, height: 40 } // Ignore top 40 pixels on Android
61+
];
4362
}
4463

64+
applyIgnoredAreas(actualImg, ignoredAreas);
65+
applyIgnoredAreas(expectedImg, ignoredAreas);
66+
4567
const numDiffPixels = pixelmatch(actualImg.data, expectedImg.data, diff.data, width, height, {
4668
threshold: 0.1,
4769
includeAA: false,
4870
diffMask: true
49-
}, (x, y) => isIgnored(x, y, ignoredAreas));
71+
});
5072

5173
const pixelTolerance = 50;
5274

0 commit comments

Comments
 (0)