Merge pull request #3 from phelma/master

can snapshot an element
This commit is contained in:
Vladimir Carrer 2018-12-04 16:43:38 +01:00 committed by GitHub
commit cf98f37284
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,6 +14,7 @@ program
.option('--w, [w]', 'width') .option('--w, [w]', 'width')
.option('--h, [h]', 'height') .option('--h, [h]', 'height')
.option('--waitfor, [waitfor]', 'Wait time in milliseconds') .option('--waitfor, [waitfor]', 'Wait time in milliseconds')
.option('--el, [el]', 'element css selector')
.parse(process.argv); .parse(process.argv);
if (program.url) urlvalue = program.url if (program.url) urlvalue = program.url
@ -35,7 +36,14 @@ console.log(fullPage);
if (program.emulate) await page.emulate(devices[program.emulate]); if (program.emulate) await page.emulate(devices[program.emulate]);
await page.goto(urlvalue) await page.goto(urlvalue)
if (program.waitfor) await page.waitFor(Number(program.waitfor)) if (program.waitfor) await page.waitFor(Number(program.waitfor))
if (program.el) {
const el = await page.$(program.el);
await el.screenshot({
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}) await page.screenshot({path: await page.title() + " " + program.emulate + " " + d.getTime() + '.png', fullPage: fullPage})
}
await page.emulateMedia('screen') await page.emulateMedia('screen')
if (program.pdf) await page.pdf({ path: await page.title() + " " + program.emulate + " " + d.getTime() + '.pdf' }) if (program.pdf) await page.pdf({ path: await page.title() + " " + program.emulate + " " + d.getTime() + '.pdf' })
console.log(await page.title()) console.log(await page.title())