SHARE
TWEET

Untitled

a guest Aug 20th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static async createPageElementScreenshotWithname(selector: string, fileName: string) {
  2. const element = await page.$(selector);
  3. if (!element) {
  4.   return;
  5. }
  6.  
  7. const rootDir = path.normalize(path.join(__dirname, '../'));
  8. const screenshotsDir = path.join(rootDir, 'test-screenshots');
  9.  
  10. const screenshotPath = path.format({
  11.   dir: screenshotsDir,
  12.   name: fileName,
  13.   ext: '.png',
  14. });
  15.  
  16. fs.mkdirSync(screenshotsDir, { recursive: true });
  17. if (element) {
  18.   Generic.logToConsole(`Creating screenshot into path ${screenshotPath}`);
  19.   try {
  20.     await element.screenshot({ path: screenshotPath });
  21.   } catch (e) {
  22.     Generic.logToConsole(`Could not take a screenshot with name ${fileName} cause: ${e}`);
  23.   }
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top