-
Notifications
You must be signed in to change notification settings - Fork 0
/
getImageDiff.js
35 lines (31 loc) · 963 Bytes
/
getImageDiff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import Rembrandt from 'rembrandt'
import fs from "fs"
export default class ImageCompare {
async compareImages(baseImagePath,ScreenShotPath){
let rembrandt = new Rembrandt({
imageA: baseImagePath,
imageB: ScreenShotPath,
renderComposition: true,
compositionMaskColor: Rembrandt.Color.RED, // Color of unmatched pixels
maxOffset: 0,
maxThreshold: 0
});
let getResults = ((result)=>{
console.log('Result is:', result.passed);
console.log('Pixel Difference:', result.differences, `Percentage Difference: ${result.percentageDifference.toFixed(5)}%`);
});
let writeImageDiffToFile = ((result)=>{
getResults(result)
let buffer = result.compositionImage
fs.writeFileSync(`../diffImages/failure-diff${Date.now()}.png`, buffer);
})
// Run the comparison
rembrandt.compare()
.then(function (result) {
result.passed == true ? getResults(result) : writeImageDiffToFile(result);
})
.catch((e) => {
console.error(e)
})
}
}