From e6a0d7bed2b2ae14159b8b582c34a64d37022aa7 Mon Sep 17 00:00:00 2001 From: ddm Date: Fri, 27 Dec 2013 14:44:36 +0100 Subject: [PATCH] [FIX] Yet another attempt to figure out UI tests on runbot bzr revid: ddm@openerp.com-20131227134436-mx8a7vid4m70sqtp --- addons/website/tests/test_ui.py | 19 ++++++++++--------- .../tests/ui_suite/banner_tour_test.js | 4 ++-- .../website/tests/ui_suite/simple_dom_test.js | 15 +++++++++++++++ .../website/tests/ui_suite/ui_test_runner.js | 7 ++++--- 4 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 addons/website/tests/ui_suite/simple_dom_test.js diff --git a/addons/website/tests/test_ui.py b/addons/website/tests/test_ui.py index 76ae3a9b8b2..ab936eb91d9 100644 --- a/addons/website/tests/test_ui.py +++ b/addons/website/tests/test_ui.py @@ -104,9 +104,7 @@ class WebsiteUiSuite(unittest.TestSuite): # EOF readable.remove(stream) else: - self.process(lines[0], result) - # the runner expects only one output line - # any subsequent line is ignored + self.process(lines, result) readable.remove(stream) if last_check_time >= (start_time + self._timeout): result.addError(self._test, "Timeout after %s s" % (last_check_time - start_time )) @@ -116,17 +114,19 @@ class WebsiteUiSuite(unittest.TestSuite): phantom.terminate() result.stopTest(self._test) - def process(self, line, result): + def process(self, lines, result): # Test protocol # ------------- # use console.log in phantomjs to output test results using the following format: # - for a success: { "event": "success" } # - for a failure: { "event": "failure", "message": "Failure description" } # - for an error: { "event": "error", "message": "Error description" } - # any other message is treated as an error + # the first line is treated as a JSON messgae + # subsequent lines are displayed only if the first line indicated an error + # or if the first line was not a JSON message (still an error) result.startTest(self._test) try: - args = json.loads(line) + args = json.loads(lines[0]) event = args.get('event', None) if event == 'success': result.addSuccess(self._test) @@ -135,13 +135,14 @@ class WebsiteUiSuite(unittest.TestSuite): result.addFailure(self._test, message) elif event == 'error': message = args.get('message', "") - result.addError(self._test, message) + result.addError(self._test, message+"\n"+"\n".join(lines[1::])) else: - result.addError(self._test, 'Unexpected JSON: "%s"' % line) + result.addError(self._test, 'Unexpected message: "%s"' % "\n".join(lines)) except ValueError: - result.addError(self._test, 'Unexpected message: "%s"' % line) + result.addError(self._test, 'Unexpected message: "%s"' % "\n".join(lines)) def load_tests(loader, base, _): base.addTest(WebsiteUiSuite('dummy_test.js', {})) + base.addTest(WebsiteUiSuite('simple_dom_test.js', { 'action': 'website.action_website_homepage' })) base.addTest(WebsiteUiSuite('banner_tour_test.js', { 'action': 'website.action_website_homepage' })) return base diff --git a/addons/website/tests/ui_suite/banner_tour_test.js b/addons/website/tests/ui_suite/banner_tour_test.js index 9bade783afc..b25b80e79c4 100644 --- a/addons/website/tests/ui_suite/banner_tour_test.js +++ b/addons/website/tests/ui_suite/banner_tour_test.js @@ -33,6 +33,6 @@ testRunner.run(function testBannerTour (page) { }, function () { console.log('{ "event": "success" }'); phantom.exit(); - }); - }); + }, 15000); + }, 5000); }); \ No newline at end of file diff --git a/addons/website/tests/ui_suite/simple_dom_test.js b/addons/website/tests/ui_suite/simple_dom_test.js new file mode 100644 index 00000000000..e0c19ceef2a --- /dev/null +++ b/addons/website/tests/ui_suite/simple_dom_test.js @@ -0,0 +1,15 @@ +var testRunner = require('./ui_test_runner.js'); + +var waitFor = testRunner.waitFor; + +testRunner.run(function simpleDomTest (page) { + waitFor(function () { + return page.evaluate(function () { + return window.openerp && window.openerp.website + && window.openerp.website.TestConsole; + }); + }, function () { + console.log('{ "event": "success" }'); + phantom.exit(); + }, 20000); +}); \ No newline at end of file diff --git a/addons/website/tests/ui_suite/ui_test_runner.js b/addons/website/tests/ui_suite/ui_test_runner.js index 75febbb4c9d..e472579a0e8 100644 --- a/addons/website/tests/ui_suite/ui_test_runner.js +++ b/addons/website/tests/ui_suite/ui_test_runner.js @@ -1,14 +1,15 @@ function waitFor(ready, callback, timeout) { - var timeoutMillis = timeout ? Math.round(timeout*1000) : 30000; + timeout = timeout || 10000; var start = new Date().getTime(); var condition = ready(); var interval = setInterval(function() { - if ((new Date().getTime() - start < timeoutMillis) && !condition ) { + if ((new Date().getTime() - start < timeout) && !condition ) { condition = ready(); } else { if(!condition) { - var message = "Timeout after "+timeoutMillis+" ms"; + var message = "Timeout after "+timeout+" ms"; console.log('{ "event": "error", "message": "'+message+'" }'); + console.log("Waiting for..."+ready); phantom.exit(1); } else { clearInterval(interval);