-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (37 loc) · 1.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const puppeteer = require('puppeteer');
const assert = require('assert');
async function GetScreenShot() {
const browser = await puppeteer.launch({ headless: false});
const page = await browser.newPage();
await page.setViewport({ width: 375, height: 677 })
await page.goto('http://localhost');
await page.screenshot({ path: 'screenshots/Page'+Math.random()+'.png' });
browser.close();
}
async function CheckTheHeadingIs()
{
const options = {
path: 'screenshots/Page'+Math.random()+'.png' ,
fullPage: false,
clip: {
x: 0,
y: 240,
width: 1000,
height: 100
}
}
const browser = await puppeteer.launch({ headless: false});
const page = await browser.newPage();
await page.setViewport({ width: 375, height: 677 });
await page.goto('https://localhost');
const headingElement = "body > div.page-section > div > div > h2";
let headingText = await page.evaluate((sel) => {
let element = document.querySelector(sel);
return element? element.innerHTML: null;
}, headingElement);
await page.screenshot(options);
browser.close();
console.log("Heading is " + headingText);
assert.equal(headingText,"Hey! Looks like you've taken a break.",);
}
CheckTheHeadingIs();