Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static async createPageElementScreenshotWithname(selector: string, fileName: string) {
- const element = await page.$(selector);
- if (!element) {
- return;
- }
- const rootDir = path.normalize(path.join(__dirname, '../'));
- const screenshotsDir = path.join(rootDir, 'test-screenshots');
- const screenshotPath = path.format({
- dir: screenshotsDir,
- name: fileName,
- ext: '.png',
- });
- fs.mkdirSync(screenshotsDir, { recursive: true });
- if (element) {
- Generic.logToConsole(`Creating screenshot into path ${screenshotPath}`);
- try {
- await element.screenshot({ path: screenshotPath });
- } catch (e) {
- Generic.logToConsole(`Could not take a screenshot with name ${fileName} cause: ${e}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement