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
|
var htmlrunner,
resultdir,
page,
fs;
phantom.injectJs("utils/core.js")
if ( phantom.args.length !== 2 ) {
console.log("Usage: phantom_test_runner.js HTML_RUNNER RESULT_DIR");
phantom.exit();
} else {
htmlrunner = phantom.args[0];
resultdir = phantom.args[1];
page = require("webpage").create();
fs = require("fs");
// Echo the output of the tests to the Standard Output
page.onConsoleMessage = function(msg, source, linenumber) {
console.log(msg);
};
page.open(htmlrunner, function(status) {
if (status === "success") {
utils.core.waitfor(function() { // wait for this to be true
return page.evaluate(function() {
return typeof(jasmine.phantomjsXMLReporterPassed) !== "undefined";
});
}, function() { // once done...
// Retrieve the result of the tests
var f = null, i, len;
suitesResults = page.evaluate(function(){
return jasmine.phantomjsXMLReporterResults;
});
// Save the result of the tests in files
for ( i = 0, len = suitesResults.length; i < len; ++i ) {
try {
f = fs.open(resultdir + '/' + suitesResults[i]["xmlfilename"], "w");
f.write(suitesResults[i]["xmlbody"]);
f.close();
} catch (e) {
console.log(e);
console.log("phantomjs> Unable to save result of Suite '"+ suitesResults[i]["xmlfilename"] +"'");
}
}
// Return the correct exit status. '0' only if all the tests passed
phantom.exit(page.evaluate(function(){
return jasmine.phantomjsXMLReporterPassed ? 0 : 1; //< exit(0) is success, exit(1) is failure
}));
}, function() { // or, once it timesout...
phantom.exit(1);
});
} else {
console.log("phantomjs> Could not load '" + htmlrunner + "'.");
phantom.exit(1);
}
});
}
|