forked from AshasTob/report-notificator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (53 loc) · 1.88 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const puppeteer = require('puppeteer');
const CREDS = require('./creds');
const NAV = require('./navigation');
async function run() {
const browser = await puppeteer.launch({
headless: true
});
const page = await browser.newPage();
await page.goto(CREDS.service, {
waituntil: "networkidle"
});
//LOGGING IN THE SYSTEM;
await page.click(NAV.nameFieldInputSelector);
await page.keyboard.type(CREDS.target.username);
await page.click(NAV.passwordFieldInputSelector);
await page.keyboard.type(CREDS.target.password);
await page.click(NAV.submitLoginButtonSelector);
//LOADED INDEX DASHBOARD. REDIRECTING TO REPORTS PAGE.
await page.waitFor(10000);
let frame = await page.frames().find(f => f.name() === NAV.iframeId);
const link = await frame.$(NAV.reportsLinkSelector);
link.click();
//REPORTS PAGE SCANNING.
await page.waitFor(10000);
frame = await page.frames().find(f => f.name() === NAV.iframeId);
const report = await frame.$(NAV.reportTableItem);
let reportText = await frame.evaluate((sel) => {
let element = document.querySelector(sel);
return element ? element.innerHTML : null;
}, NAV.reportTableItem);
console.log(reportText);
var Message = require("./message.js");
var message = new Message(
'bratokokok@gmail.com',
'bratokokok@gmail.com',
'Reports notification',
''
);
if (reportText === CREDS.target.errorText) {
message.setText("There is an issue. Missing report on " + new Date());
console.log(message.text);
var Slacker = require("./slacker.js");
var slacker = new Slacker();
var Mailer = require("./mailer.js");
var mailer = new Mailer();
mailer.send(message);
slacker.send(message);
} else {
console.log("All is good");
}
browser.close();
}
run();