From 305cb38efc0d57d12e9145000f83a7de88457b81 Mon Sep 17 00:00:00 2001 From: Wolfram Schneider Date: Fri, 31 Jan 2014 10:46:45 +0000 Subject: [PATCH] improve error handling for failed URLs --- test/phantom/evaluate.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/test/phantom/evaluate.js b/test/phantom/evaluate.js index e7cc91f..949e036 100644 --- a/test/phantom/evaluate.js +++ b/test/phantom/evaluate.js @@ -35,6 +35,7 @@ function wait_for_jasmine(checkFx, readyFx, failFx, timeout) { // success if (condition) { // console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms."); + result.time = (new Date().getTime() - start); readyFx(result); clearInterval(interval); phantom.exit(0); @@ -50,7 +51,8 @@ function wait_for_jasmine(checkFx, readyFx, failFx, timeout) { // checking else { result = checkFx(); - condition = result.mkws.jasmine_done; + if (result) + condition = result.mkws.jasmine_done; } }, 500); //< repeat check every N ms @@ -60,23 +62,30 @@ function wait_for_jasmine(checkFx, readyFx, failFx, timeout) { page.open(url, function (status) { console.log("fetch " + url + " with status: " + status); - console.log("polling MKWS test status..."); + if (status != 'success') { + console.log("Failed to fetch page, give up"); + phantom.exit(1); + } + + console.log("polling MKWS jasmine test status..."); var exit = wait_for_jasmine(function () { return page.evaluate(function () { - return { - mkws: window.mkws, - duration: window.$(".duration").text(), - passing: window.$(".passingAlert").text() - }; + if (!window || !window.$ || !window.mkws) { + return false; + } else { + return { + mkws: window.mkws, + duration: window.$(".duration").text(), + passing: window.$(".passingAlert").text() + }; + } })}, function(result) { - if (result.mkws.jasmine_done) { - console.log("MKWS tests are successfully done. Hooray!"); - console.log("jasmine duration: " + result.duration); - console.log("jasmine passing: " + result.passing); - } + 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); }, function (result) { @@ -86,5 +95,4 @@ page.open(url, function (status) { page.render(error_png); }, run_time * 1000); - }); -- 1.7.10.4