-
Notifications
You must be signed in to change notification settings - Fork 5
/
PhantomVerifyTask.js
executable file
·108 lines (96 loc) · 2.61 KB
/
PhantomVerifyTask.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
var page = new WebPage(),
stepIndex = 0,
loadInProgress = false,
maxRetrys = 5,
intervalDelay = 2000,
retrys = 0,
args = require('system').args;
// if (args.length === 1) {
// console.log('Try to pass some arguments when invoking this script!');
// } else {
// args.forEach(function(arg, i) {
// console.log(i + ': ' + arg);
// });
// }
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.onLoadStarted = function() {
loadInProgress = true;
console.log("load started");
};
page.onLoadFinished = function() {
loadInProgress = false;
console.log("load finished");
};
// page.onAlert = function(msg) {
// console.log("Alert! - " + msg);
// }
var steps = [
function enterLogin(cb) {
//Load Login Page
page.open("https://buzzport.gatech.edu/cp/home/displaylogin", function() {
var status = page.evaluate(function() {
if(document.title == "BuzzPort Login") {
document.getElementById('login_btn').click();
return "success";
} else{
//couldn't reach login entrance
return "failure";
}
});
cb(status);
});
},
function loginSubmit(cb) {
//Enter Credentials and login to buzzport
var status = page.evaluate(function(username, password) {
if(document.title=="GT | GT Login") {
document.getElementById("username").value = username;
document.getElementById("password").value = password;
document.getElementsByClassName("btn-submit")[0].click();
return "success";
} else{
//haven't loaded GT login page yet, so
return "failure";
}
}, args[1], args[2]);
cb(status);
},
function confirmLogin(cb) {
// Buzzport page.
var status = page.evaluate(function() {
if(document.title=="BuzzPort") {
//confirm login
// console.log(document.querySelectorAll('html')[0].outerHTML);
return "success";
} else{
//couldn't confirm
return "failure";
}
});
cb(status);
}
];
setInterval(function() {
if (!loadInProgress && typeof steps[stepIndex] == "function") {
steps[stepIndex](function(status) {
if(status=="success") {
stepIndex++;
retrys = 0;
} else{
retrys = retrys + 1;
if(retrys > maxRetrys) {
//task failure condition
console.log("VERIFICATION_FAILURE");
phantom.exit();
}
}
});
}
if (typeof steps[stepIndex] != "function") {
//task success condition
console.log("VERIFICATION_SUCCESS");
phantom.exit();
}
}, intervalDelay);