Skip to content

Commit 7c9fa16

Browse files
committed
Tolerate percentage instead of fixed pixels
1 parent 7e3bd9c commit 7c9fa16

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

maestro/helpers/compare_screenshots.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,17 @@ fs.readdirSync(actualDir).forEach(file => {
7171
diffMask: true
7272
});
7373

74-
const pixelTolerance = 50;
75-
74+
const tolerancePercent = 0.02; // 2%
75+
const totalPixels = width * height;
76+
const pixelTolerance = Math.floor(totalPixels * tolerancePercent);
77+
7678
if (numDiffPixels > pixelTolerance) {
7779
fs.writeFileSync(diffPath, PNG.sync.write(diff));
7880
failedComparisons.push(file);
79-
console.log(`❌ Comparison failed for ${file}`);
81+
console.log(`❌ Comparison failed for ${file} (diff: ${numDiffPixels} > tolerance: ${pixelTolerance})`);
8082
} else {
8183
fs.appendFileSync(path.join(__dirname, '../../compare_output.txt'), `✅ Comparison passed for ${file}\n`);
82-
console.log(`✅ Comparison passed for ${file}`);
84+
console.log(`✅ Comparison passed for ${file} (diff: ${numDiffPixels} <= tolerance: ${pixelTolerance})`);
8385
}
8486
} else {
8587
console.log(`⚠️ Expected file not found for ${file}`);
-204 KB
Binary file not shown.
22.6 KB
Loading

0 commit comments

Comments
 (0)