X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=test%2Fphantom%2Fevaluate.js;h=0cf56f0d52a5fe74afb0c4914afb4d660bbefcaa;hb=5a126c522666307f9dffd7835c70fe1889d276cc;hp=bb6a5375cff5b9eac277297de9834c45ac83fff7;hpb=2b7e272dc1072cf1cb80769f40a5cbbb16c30f03;p=mkws-moved-to-github.git diff --git a/test/phantom/evaluate.js b/test/phantom/evaluate.js index bb6a537..0cf56f0 100644 --- a/test/phantom/evaluate.js +++ b/test/phantom/evaluate.js @@ -14,14 +14,21 @@ if (system.args.length === 1) { } var url = system.args[1]; +var run_time = 8; // poll up to seconds +if (system.args[2] && parseFloat(system.args[2]) > 0) { + run_time = parseFloat(system.args[2]); +} + page.viewportSize = { width: 1200, height: 1000 }; -var run_time = 8; // poll up to seconds -if (system.args[2] && parseFloat(system.args[2]) > 0) { - run_time = parseFloat(system.args[2]); +// 0: silent, 1: some infos, 2: display console.log() output +var debug = 2; +if (typeof system.env['DEBUG'] != 'undefined' && parseInt(system.env['DEBUG']) != NaN) { + debug = system.env['DEBUG']; + if (debug > 0) console.log("reset debug level to: " + debug); } /************************/ @@ -32,7 +39,7 @@ function wait_for_jasmine(checkFx, readyFx, failFx, timeout) { result, condition = false; var interval = setInterval(function () { - console.log("."); + if (debug == 1) console.log("."); // success if (condition) { @@ -59,33 +66,55 @@ function wait_for_jasmine(checkFx, readyFx, failFx, timeout) { }, 500); //< repeat check every N ms }; +// redirect webkit console.log() output +page.onConsoleMessage = function (message) { + if (debug >= 2) console.log(message); +}; + +// cat webkit alert() +page.onAlert = function (msg) { + console.log("Alert: " + msg); +}; +// display HTTP errors +page.onResourceError = function (resourceError) { + // console.log('phantomjs error code: ' + resourceError.errorCode); + console.log(resourceError.errorString); + phantom.exit(3); +}; page.open(url, function (status) { - console.log("fetch " + url + " with status: " + status); + if (debug >= 1) console.log("fetch " + url + " with status: " + status); + if (status != 'success') { - console.log("Failed to fetch page, give up"); + console.log("Failed to fetch page, give up. Network error?"); phantom.exit(1); } - console.log("polling MKWS jasmine test status for " + run_time + " seconds"); + if (debug >= 1) console.log("polling MKWS jasmine test status for " + run_time + " seconds"); + var exit = wait_for_jasmine(function () { return page.evaluate(function () { if (!window || !window.$ || !window.mkws) { return false; } else { + var passing = window.$(".passingAlert").text() || window.$(".failingAlert").text(); + return { mkws: window.mkws, html: window.$("html").html(), duration: window.$(".duration").text(), - passing: window.$(".passingAlert").text() + passing: passing }; } }) }, function (result) { + if (debug < 1) return; + + console.log(""); console.log("MKWS tests are successfully done in " + result.time / 1000 + " seconds. Hooray!"); console.log("jasmine duration: " + result.duration); console.log("jasmine passing: " + result.passing);