[IMP] website test: add a timeout in phantom js to raise a better error and improve...
authorChristophe Matthieu <chm@openerp.com>
Fri, 7 Feb 2014 07:47:45 +0000 (08:47 +0100)
committerChristophe Matthieu <chm@openerp.com>
Fri, 7 Feb 2014 07:47:45 +0000 (08:47 +0100)
bzr revid: chm@openerp.com-20140207074745-ffrcoi2aj5m67i8m

addons/website/static/src/js/website.tour.js
addons/website/tests/test_ui.py
addons/website/tests/ui_suite/ui_test_runner.js

index 4285656..25d8ac8 100644 (file)
@@ -75,9 +75,8 @@ website.Tour = openerp.Class.extend({
 
         website.Tour.busy = true;
 
-        if (automatic) {
-            this.localStorage.setItem("tour-"+this.id+"-test-automatic", true);
-        }
+        this.localStorage.setItem("tour-"+this.id+"-test-automatic", automatic);
+        this.automatic = automatic;
 
         if (this.path) {
             // redirect to begin of the tour in function of the language
@@ -93,12 +92,13 @@ website.Tour = openerp.Class.extend({
         website.Tour.waitReady.call(this, function () {self._running();});
     },
     running: function () {
+        var self = this;
         if (+this.localStorage.getItem("tour-"+this.id+"-test") >= this.steps.length-1) {
             this.endTour();
             return;
         }
 
-        if (website.Tour.is_busy() || !this.testPathUrl()) return;
+        if (website.Tour.is_busy()) return;
 
         // launch tour with url
         this.checkRunningUrl();
@@ -106,6 +106,21 @@ website.Tour = openerp.Class.extend({
         // mark tour as busy (only one test running)
         if (this.localStorage.getItem("tour-"+this.id+"-test") != null) {
             website.Tour.busy = true;
+            this.automatic = !!this.localStorage.getItem("tour-"+this.id+"-test-automatic");
+        }
+
+        if (!this.testPathUrl()) {
+            if (this.automatic) {
+                this.timer = setTimeout(function () {
+                    self.reset();
+                    throw new Error("Wrong url for running " + self.id
+                        + '\ntestPath: ' + self.testPath
+                        + '\nhref: ' + window.location.href
+                        + "\nreferrer: " + document.referrer
+                    );
+                },this.defaultOverLaps);
+            }
+            return;
         }
 
         var self = this;
@@ -115,7 +130,6 @@ website.Tour = openerp.Class.extend({
         var stepId = this.localStorage.getItem("tour-"+this.id+"-test");
 
         if (stepId != null) {
-            this.automatic = !!this.localStorage.getItem("tour-"+this.id+"-test-automatic");
             this.registerTour();
             this.nextStep(stepId,  this.automatic ? this.autoNextStep : null, this.automatic ? this.defaultOverLaps : null);
         }
index a9c8076..3c30dc8 100644 (file)
@@ -41,7 +41,7 @@ class WebsiteUiSuite(unittest.TestSuite):
     # timeout in seconds
     def __init__(self, testfile, options, timeout=60.0):
         self._testfile = testfile
-        self._timeout = timeout
+        self._timeout = timeout + 5.0
         self._options = options
         self._test = None
         self._ignore_filters = [
index dd023ee..f759ea6 100644 (file)
@@ -20,11 +20,9 @@ function waitFor (ready, callback, timeout, timeoutMessageCallback) {
 }
 
 function run (test, onload, inject) {
-    try {
-
     var options = JSON.parse(phantom.args);
 
-    var timeout = options.timeout ? Math.round(parseFloat(options.timeout)*1000) : 60000;
+    var timeout = options.timeout ? Math.round(parseFloat(options.timeout)*1000-5000) : 60000;
 
     var scheme = options.scheme ? options.scheme+'://' : 'http://';
     var host = options.host ? options.host : 'localhost';
@@ -96,14 +94,14 @@ function run (test, onload, inject) {
     
     var maxRetries = 10;
     var retryDelay = 1000; // ms
-    var tries = 0; 
+    var tries = 0;
     page.open(url, function openPage (status) {
         if (status !== 'success') {
             tries++;
             if (tries < maxRetries) {
-               setTimeout(function () {
-                       page.open(url, openPage);
-               }, retryDelay);
+                setTimeout(function () {
+                    page.open(url, openPage);
+                }, retryDelay);
             } else {
                 console.log('{ "event": "error", "message": "'+url+' failed to load '+tries+' times ('+status+')"}');
                 phantom.exit(1);
@@ -116,15 +114,19 @@ function run (test, onload, inject) {
 
     });
 
-    } catch (e) {
-        console.error("Error in run:", e);
-        phantom.exit(1);
-    }
+    setTimeout(function () {
+        page.evaluate(function (timeout) {
+            var message = ("Timeout after " +(timeout/1000)+ " s"
+                + "\nhref: " + window.location.href
+                + "\nreferrer: " + document.referrer
+                + "\n\n" + document.body.innerHTML).replace(/[^a-z0-9\s~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "*");
+            console.log(JSON.stringify({ "event": "error", "message": message}));
+            phantom.exit(1);
+        },timeout);
+    }, timeout);
 }
 
 function run_test (testname, options) {
-    try {
-
     options = options || {};
     run(
         function start (page, timeout) {
@@ -146,11 +148,6 @@ function run_test (testname, options) {
         },
         options.inject || null
     );
-
-    } catch (e) {
-        console.error("Error in run_test:", e);
-        phantom.exit(1);
-    }
 }
 
 module.exports = {