Skip to content

Instantly share code, notes, and snippets.

@tristansokol
Created August 20, 2018 22:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tristansokol/dabdd78bab1d4d09cb7ccf3540f3a661 to your computer and use it in GitHub Desktop.
Save tristansokol/dabdd78bab1d4d09cb7ccf3540f3a661 to your computer and use it in GitHub Desktop.
await page.goto('https://www.wikihow.com/Tie-Your-Shoes');
await page.waitForSelector('#article_shell');
await page.screenshot({
path: './production.png',
fullPage: false,
})
await page.goto('https://www.wikihow.com/Tie-Your-Shoes');
await page.waitForSelector('#article_shell');
await page.screenshot({
path: './local.png',
fullPage: false,
})
let img1 = fs.createReadStream('./production.png')
.pipe(new PNG()).on('parsed', doneReading)
.on('error', function () { reject() });
let img2 = fs.createReadStream('./local.png')
.pipe(new PNG()).on('parsed', doneReading)
.on('error', function () { reject() });
let filesRead = 0
function doneReading() {
if (++filesRead < 2) return;
var diff = new PNG({ width: img1.width, height: img1.height });
pixelmatch(img1.data, img2.data, diff.data, img1.width, img1.height, { threshold: 0.1 });
diff.pack().pipe(fs.createWriteStream('diff.png'));
resolve()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment