Fetch a mkws/jasmine based page into node.js, evaluate the page and check if test...
authorWolfram Schneider <wosch@indexdata.dk>
Thu, 30 Jan 2014 22:08:38 +0000 (22:08 +0000)
committerWolfram Schneider <wosch@indexdata.dk>
Thu, 30 Jan 2014 22:08:38 +0000 (22:08 +0000)
This should make it possible to run the test on the command line in jenkins.

e.g.:

$ phantomjs evaluate.js https://mkws-dev.indexdata.com/jasmine-popup.html
fetch https://mkws-dev.indexdata.com/jasmine-popup.html with status: success
.
.
.
.
.
successfully done

test/spec-dev/evaluate.js [new file with mode: 0644]

diff --git a/test/spec-dev/evaluate.js b/test/spec-dev/evaluate.js
new file mode 100644 (file)
index 0000000..922f205
--- /dev/null
@@ -0,0 +1,41 @@
+var page = require('webpage').create(),
+    system = require('system');
+
+if (system.args.length === 1) {
+    console.log('Usage: screenshot.js <some URL>');
+    phantom.exit();
+}
+var url = system.args[1];
+
+page.viewportSize = {
+    width: 1200,
+    height: 1000
+};
+
+var run_time = 12; // poll up to seconds
+page.open(url, function (status) {
+    console.log("fetch " + url + " with status: " + status);
+
+    for (var i = 1; i < run_time; i++) {
+        setTimeout(function () {
+            var result = page.evaluate(function (s) {
+                // return document.querySelector(s).innerText;
+                return {
+                    mkws: window.mkws,
+                    string: "foo"
+                };
+            }, 'title');
+
+            console.log(".");
+            if (result.mkws.jasmine_done) {
+               console.log("successfully done");
+               phantom.exit(0);
+           }
+        }, i * 1000);
+    }
+
+    setTimeout(function () {
+       console.log("failed after " + run_time + " seconds");
+        phantom.exit(1);
+    }, run_time * 1000);
+});