From d5a71d8b5c7b95ba3586d78758995332c6aac06a Mon Sep 17 00:00:00 2001 From: Phil Helm Date: Tue, 4 Dec 2018 15:23:06 +0000 Subject: [PATCH 1/2] can snapshot an element --- index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c7fde0b..c1965ee 100755 --- a/index.js +++ b/index.js @@ -14,6 +14,7 @@ program .option('--w, [w]', 'width') .option('--h, [h]', 'height') .option('--waitfor, [waitfor]', 'Wait time in milliseconds') + .option('--el, [el]', 'element css selector') .parse(process.argv); if (program.url) urlvalue = program.url @@ -35,7 +36,21 @@ console.log(fullPage); if (program.emulate) await page.emulate(devices[program.emulate]); await page.goto(urlvalue) if (program.waitfor) await page.waitFor(Number(program.waitfor)) - await page.screenshot({path: await page.title() + " " + program.emulate + " " + d.getTime() + '.png', fullPage: fullPage}) + if (program.el) { + const el = await page.$(program.el); + await el.screenshot({ + path: + (await page.title()) + + ' ' + + program.emulate + + ' ' + + d.getTime() + + program.el + + '.png' + }); + } else { + await page.screenshot({path: await page.title() + " " + program.emulate + " " + d.getTime() + '.png', fullPage: fullPage}) + } await page.emulateMedia('screen') if (program.pdf) await page.pdf({ path: await page.title() + " " + program.emulate + " " + d.getTime() + '.pdf' }) console.log(await page.title()) From 75a3e55a475f1b34b1006fd884723f4bc30d5903 Mon Sep 17 00:00:00 2001 From: Phil Helm Date: Tue, 4 Dec 2018 15:35:24 +0000 Subject: [PATCH 2/2] clean --- index.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/index.js b/index.js index c1965ee..aeb67eb 100755 --- a/index.js +++ b/index.js @@ -39,14 +39,7 @@ console.log(fullPage); if (program.el) { const el = await page.$(program.el); await el.screenshot({ - path: - (await page.title()) + - ' ' + - program.emulate + - ' ' + - d.getTime() + - program.el + - '.png' + path: `${await page.title()} ${program.emulate} ${program.el} ${d.getTime()}.png` }); } else { await page.screenshot({path: await page.title() + " " + program.emulate + " " + d.getTime() + '.png', fullPage: fullPage})