2 Fetch a mkws/jasmine based page into node.js, evaluate the page and check if test status
3 This should make it possible to run the test on the command line in jenkins. e.g.:
5 phantomjs evaluate.js https://mkws-dev.indexdata.com/jasmine-local-popup.html
8 var page = require('webpage').create(),
9 system = require('system');
11 if (system.args.length === 1) {
12 console.log('Usage: screenshot.js <some URL>');
15 var url = system.args[1];
22 var run_time = 12; // poll up to seconds
24 /************************/
26 function wait_for_jasmine(checkFx, readyFx, failFx, timeout) {
27 var max_timeout = timeout ? timeout : run_time * 1000,
28 start = new Date().getTime(),
32 var interval = setInterval(function() {
37 // console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
39 clearInterval(interval);
44 else if ( new Date().getTime() - start >= max_timeout ) {
45 result.time = (new Date().getTime() - start);
53 condition = result.mkws.jasmine_done;
56 }, 500); //< repeat check every N ms
61 page.open(url, function (status) {
62 console.log("fetch " + url + " with status: " + status);
63 console.log("polling MKWS test status...");
65 var exit = wait_for_jasmine(function () {
66 return page.evaluate(function () {
69 duration: window.$(".duration").text(),
70 passing: window.$(".passingAlert").text()
75 if (result.mkws.jasmine_done) {
76 console.log("MKWS tests are successfully done. Hooray!");
77 console.log("jasmine duration: " + result.duration);
78 console.log("jasmine passing: " + result.passing);
83 var error_png = "./mkws-error.png";
84 console.log("MKWS tests failed after " + result.time/1000 + " seconds");
85 console.log("keep screenshot in '" + error_png + "'");
86 page.render(error_png);