documentation
[mkws-moved-to-github.git] / test / spec-dev / evaluate.js
1 /*
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.:
4     
5       phantomjs evaluate.js https://mkws-dev.indexdata.com/jasmine-local-popup.html
6 */
7
8 var page = require('webpage').create(),
9     system = require('system');
10
11 if (system.args.length === 1) {
12     console.log('Usage: screenshot.js <some URL>');
13     phantom.exit();
14 }
15 var url = system.args[1];
16
17 page.viewportSize = {
18     width: 1200,
19     height: 1000
20 };
21
22 var run_time = 12; // poll up to seconds
23 page.open(url, function (status) {
24     console.log("fetch " + url + " with status: " + status);
25     console.log("polling MKWS test status...");
26
27     for (var i = 1; i < run_time; i++) {
28         setTimeout(function () {
29             var result = page.evaluate(function (s) {
30                 // return document.querySelector(s).innerText;
31                 return {
32                     mkws: window.mkws,
33                     string: "foo"
34                 };
35             }, 'title');
36
37             console.log(".");
38             if (result.mkws.jasmine_done) {
39                 console.log("MKWS tests are successfully done. Hooray!");
40                 phantom.exit(0);
41             }
42         }, i * 1000);
43     }
44
45     setTimeout(function () {
46         console.log("MKWS tests failed after " + run_time + " seconds");
47         phantom.exit(1);
48     }, run_time * 1000);
49 });