forked from selombanybah/Learncode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphantom_driver.js
More file actions
31 lines (29 loc) · 921 Bytes
/
Copy pathphantom_driver.js
File metadata and controls
31 lines (29 loc) · 921 Bytes
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
var page = require('webpage').create();
page.open("http://localhost:3000/test/index.html", function (status) {
if (status != "success") {
console.log("page couldn't be loaded successfully");
phantom.exit(1);
}
waitFor(function () {
return page.evaluate(function () {
var output = document.getElementById('status');
if (!output) { return false; }
return (/^(\d+ failures?|all passed)/i).test(output.innerText);
});
}, function () {
var failed = page.evaluate(function () { return window.failed; });
var output = page.evaluate(function () {
return document.getElementById('output').innerText + "\n" +
document.getElementById('status').innerText;
});
console.log(output);
phantom.exit(failed > 0 ? 1 : 0);
});
});
function waitFor (test, cb) {
if (test()) {
cb();
} else {
setTimeout(function () { waitFor(test, cb); }, 250);
}
}