NimaSoroush / differencify

Differencify is a library for visual regression testing
MIT License
634 stars 46 forks source link

Unable to take particular 'Div' screenshot #116

Closed voletiswaroop closed 5 years ago

voletiswaroop commented 5 years ago

I have a scenario where I have to take a screenshot of the particular 'div/section' which is not happening with page.screenshot().

Thanks in Advance.

NimaSoroush commented 5 years ago

Hi @voletiswaroop , this is already supported scenario as Differencify supports full Puppeteer API. By Puppeteer API you can use elementHandle.screenshot method to take a screenshot of an element. Something like this should work,

(async () => {
  const target = differencify.init({ chain: false });
  await target.launch();
  const page = await target.newPage();
  await page.goto('https://www.skyscanner.net/');
  const legalInfoHandle = await page.$('.legal-info__copyright');
  const image = await legalInfoHandle.screenshot();
  const result = await target.toMatchSnapshot(image)
  await page.close();
  await target.close();
  console.log(result);
})();
NimaSoroush commented 5 years ago

Please reopen the issue if needed. Thanks

voletiswaroop commented 5 years ago

Thank you so much @NimaSoroush