-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlemonade.js
240 lines (193 loc) · 7.58 KB
/
lemonade.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
const puppeteer = require('puppeteer');
const CREDS = require('./creds');
var DEBUG = true;
if(process.argv[2] == 'prod'){
DEBUG = false;
}
console.log("DEBUG: " + DEBUG);
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
// Browse to page
await page.goto(CREDS.loginURL, { waitUntil: 'networkidle2' });
// Enter login credentials
await page.click('#ctl00_content_SiteThemeContentFragmentPage1_fragment_3526_ctl01_ctl00_LoginForm1_ctl06_username');
await page.keyboard.type(CREDS.username);
await page.click('#ctl00_content_SiteThemeContentFragmentPage1_fragment_3526_ctl01_ctl00_LoginForm1_ctl06_password');
await page.keyboard.type(CREDS.password);
// Login
console.log('Logging in');
await page.click('#ctl00_content_SiteThemeContentFragmentPage1_fragment_3526_ctl01_ctl00_LoginForm1_ctl06_loginButton');
console.log('Letting page load...');
await page.waitForNavigation();
await page.waitFor(4 * 1000);
// Enumerate active tasks 'tracker'
console.log('Finding tasks');
let listLength = await page.evaluate((sel) => {
return document.getElementsByClassName(sel).length;
}, 'tracker');
var tasks = [];
for (let i = 0; i < listLength; i++) {
let title = await page.evaluate((index) => {
let element = document.getElementsByClassName('tracker')[index];
return element ? element.getAttribute('aria-label') : null;
}, i);
if (title == null)
continue;
console.log('Found Task ' + ': ' + title);
tasks.push({ title: title });
}
for (let i = 0; i < tasks.length; i++) {
var task = tasks[i];
console.log('Processing Task: ' + task.title);
var handler = taskHandlers[task.title];
if (handler == null) {
console.error("No handler found for task: " + task.title);
continue;
}
try {
await handler(task, browser, page);
} catch (ex) {
console.error("Error while handling task. Please provide error.png and a copy of the following error message to the developer.", ex);
await page.screenshot({ path: 'error.png' });
}
}
console.log('Done!');
await browser.close();
})();
var taskHandlers = {
"Complete Your Well-being Assessment": function (task, browser, page) {
console.log("This task must be completed manually");
},
"Leidos Integrity Pledge": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Register for the Livongo Diabetes Management Program": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Check Your Glucose with Livongo": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Share Your 2019 Well-Being Resolution": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Dental Exam": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Vision Exam": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Preventive Screenings": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Teladoc Consultation": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Condition Management Programs": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Tobacco Cessation Challenge": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Understanding the Opioid Epidemic": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Learn More About Mission For Life": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Create a Profile in the Prudential Financial Wellness Center": async function (task, browser, page) {
console.log("This task must be completed manually");
},
"Track Your Progress": async function (task, browser, page) {
console.log("No Action Required");
},
"Download the Mobile App": async function (task, browser, page) {
await SimpleJoinAndTrack(task, browser, page);
},
"Attend a FREE EAP Wellness Seminar": async function (task, browser, page) {
console.log("This task must be completed manually because they may ask for your certificate of completion");
},
"Connect a Device or App": async function (task, browser, page) {
await SimpleJoinAndTrack(task, browser, page);
},
"150 Minutes of Exercise Per Week": async function (task, browser, page) {
await OpenTask(task, browser, page);
await JoinTask(task, browser, page);
// Enter time and track
await page.evaluate(() => {
document.getElementById('numericinput').value = 30;
document.getElementsByClassName('button-track')[0].click();
});
await page.waitFor(2 * 1000);
await CloseTask(task, browser, page);
},
"Take Time to Recharge": async function (task, browser, page) {
var now = new Date();
if (now.getDay() == 0 || now.getDay() == 6) {
console.log("Skipping due to weekend");
return;
}
await SimpleJoinAndTrack(task, browser, page);
},
};
async function GoThroughSlideshow(page, slideCount) {
for (var i = 0; i < slideCount; i++) {
await page.click('#html5Experience > div.PresentationHost > div.PresentationHostRightScroller.PresentationHostArrowHover > div');
await page.waitFor(1000);
}
}
async function StartQuiz(page) {
await page.click("#startQuiz");
await page.waitFor(1000);
}
async function PickQuizOption(page, option) {
await page.click("#html5Experience > div.Player2QuizContainer > div:nth-child(" + option + ") > div.Player2QuestionContainerWrapper > div:nth-child(2) > label > input");
await page.waitFor(1000);
await page.click("#html5Experience > div.Player2QuizContainer > div.Player2NextButtonContainer > div");
await page.waitFor(1000);
await page.click("#html5Experience > div.Player2QuizContainer > div.Player2NextButtonContainer > div");
await page.waitFor(1000);
}
async function OpenTask(task, browser, page) {
await page.evaluate((title) => {
document.querySelector('[aria-label="' + title + '"]').click();
}, task.title);
await page.waitFor(6 * 1000);
}
async function JoinTask(task, browser, page) {
if (DEBUG)
return;
let justJoined = await page.evaluate(() => {
let element = document.getElementsByClassName('button-join')[0];
if (element == null) {
return false;
} else {
element.click();
return true;
}
});
if (justJoined) {
console.log('Just joined...');
await page.waitFor(6 * 1000);
}
}
async function SimpleTrack(task, browser, page) {
if (DEBUG)
return;
await page.evaluate(() => {
document.getElementsByClassName('button-track')[0].click();
});
}
async function CloseTask(task, browser, page) {
await page.evaluate(() => {
document.getElementsByClassName('item-info-close')[0].click();
});
await page.waitFor(2 * 1000);
}
async function SimpleJoinAndTrack(task, browser, page) {
console.log('Performing simple join and track');
await OpenTask(task, browser, page);
await JoinTask(task, browser, page);
await SimpleTrack(task, browser, page);
await CloseTask(task, browser, page);
}