-
Notifications
You must be signed in to change notification settings - Fork 3
/
tester.js
83 lines (68 loc) · 2.81 KB
/
tester.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const puppeteer = require('puppeteer');
const CronJob = require('cron').CronJob;
const $ = require('cheerio');
const nodemailer = require('nodemailer');
const chromeoptions = {
executablepath: 'Eneter your chrome.exe file path here',
headless: false,
slowMo: 8,
defaultViewport: null
};
(async() => {
const browser = await puppeteer.launch(chromeoptions);
const page = await browser.newPage();
page.setDefaultNavigationTimeout(0);
await page.goto('https://cgifederal.secure.force.com/');
await page.type('.stylizedInput1', 'Example@gmail.com');// Username Email Dummy Account
await page.type('[id*=password]', 'tester'); // Password for Dummy account
await page.$$eval("input[type='checkbox']", checks => checks.forEach(c => c.checked = true));
await page.waitFor(6000);
await Promise.all([
page.waitForNavigation(), page.click('[id*=loginButton]')
]).catch(() => { console.error("Error Occured.") });
async function RelaodPageOnce() {
await page.evaluate(() => {
location.reload(true)
});
}
async function sendNotification(availableDate) {
var dtb = new Date();
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'Enter Your Primary Email ID from where you want to sent email when Counslor Dates are available',
pass: 'Password Of Gmail Account'
}
});
let textToSend = 'Date is Available : ' + availableDate + " AT " + dtb;
let info = await transporter.sendMail({
from: '"User name" <emailId from where email will be sent when BB is availble >',
to: "Recipient Email ID ",
subject: 'Date Available ' + availableDate,
text: textToSend,
});
console.log("Message sent: %s", info.messageId);
}
async function checkBBAval() {
RelaodPageOnce();
await page.waitForNavigation();
let html = await page.evaluate(() => document.body.innerHTML);
$('.leftPanelText', html).each(function() {
var currentvalBB = $(this).text();
if (typeof(currentvalBB) != 'undefined' && currentvalBB != null) {
var dt = new Date();
console.log("**************************************\n");
console.log("currentvalBB is available for : " + currentvalBB + " AT " + dt);
console.log("\n**************************************\n");
sendNotification(currentvalBB);
}
});
}
async function startTracking() {
let job = new CronJob('* * * * *', function() { //runs every 1 minutes in this config
checkBBAval();
}, null, true, null, null, true);
job.start();
}
startTracking();
})();