Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement