[IMP] tests: replace browser_js success and failure strings

When evaluating js tests using the browser_js method, they are
considered a success when 'ok' is found in the console log and a failure
if 'error' is found instead.

This is not very robust and recently failed with this commit : 7410de111f
It adds a filter named 'Error' in a view, when the 'click_all' test
clicks on this filter, a message with the name of the filter is written
in the console, wrongly leading to a test failure.

With this commit, the browser_js method expects a log message in the
browser console with the explicit text "test successful".
On the other hand, any error in the console log will lead to a test
failure but a test can be forced to fail with the explicit error message
in the browser console "test failed".

As a bonus, the python logger should now also log browser js trace messages.

closes odoo/odoo#31158
This commit is contained in:
Christophe Monniez
2019-02-19 08:06:07 +00:00
parent 83e6faf9a2
commit fec86404e7
6 changed files with 16 additions and 23 deletions
+2 -2
View File
@@ -70,11 +70,11 @@
return testDef.then(function() {
console.log("Successfully tested ", testedApps.length, " apps");
console.log("Successfully tested ", testedMenus.length - testedApps.length, " menus");
console.log("ok");
console.log("test successful");
}).always(function() {
console.log("Test took ", (performance.now() - startTime)/1000, " seconds");
}).fail(function () {
console.error("Error !");
console.error("test failed");
});
}
@@ -48,9 +48,9 @@ var sortButtonAppended = false;
*/
QUnit.done(function(result) {
if (!result.failed) {
console.log('ok');
console.log('test successful');
} else {
console.log('error');
console.error('test failed');
}
if (!sortButtonAppended) {
@@ -343,10 +343,10 @@ return core.Class.extend(mixins.EventDispatcherMixin, ServicesMixin, {
});
console.log(document.body.parentElement.outerHTML);
console.error(error); // will be displayed as error info
console.log("error"); // phantomJS wait for message starting by error to stop
console.error("test failed"); // browser_js wait for error message "test failed"
} else {
console.log(_.str.sprintf("Tour %s succeeded", tour_name));
console.log("ok"); // phantomJS wait for exact message "ok"
console.log("test successful"); // browser_js wait for message "test successful"
}
this._log = [];
} else {
+1 -1
View File
@@ -42,7 +42,7 @@ class TestUiTranslate(odoo.tests.HttpCase):
class TestUi(odoo.tests.HttpCase):
def test_01_public_homepage(self):
self.phantom_js("/", "console.log('ok')", "'website.content.snippets.animation' in odoo.__DEBUG__.services")
self.phantom_js("/", "console.log('test successful')", "'website.content.snippets.animation' in odoo.__DEBUG__.services")
def test_02_admin_tour_banner(self):
self.phantom_js("/", "odoo.__DEBUG__.services['web_tour.tour'].run('banner')", "odoo.__DEBUG__.services['web_tour.tour'].tours.banner.ready", login='admin')
@@ -507,7 +507,7 @@ class TestAssetsBundleInBrowser(HttpCase):
"""
self.phantom_js(
"/test_assetsbundle/js",
"a + b + c === 6 ? console.log('ok') : console.log('error')",
"a + b + c === 6 ? console.log('test successful') : console.log('error')",
login="admin"
)
@@ -532,7 +532,7 @@ class TestAssetsBundleInBrowser(HttpCase):
self.phantom_js(
"/test_assetsbundle/js",
"a + b + c + d === 10 ? console.log('ok') : console.log('error')",
"a + b + c + d === 10 ? console.log('test successful') : console.log('error')",
login="admin",
)
+7 -14
View File
@@ -734,26 +734,19 @@ class ChromeBrowser():
if res.get('result', {}).get('result').get('subtype', '') == 'error':
self._logger.error("Running code returned an error")
return False
elif res and res.get('method') == 'Runtime.consoleAPICalled' and res.get('params', {}).get('type') in ('log', 'error'):
elif res and res.get('method') == 'Runtime.consoleAPICalled' and res.get('params', {}).get('type') in ('log', 'error', 'trace'):
logs = res.get('params', {}).get('args')
log_type = res.get('params', {}).get('type')
content = " ".join([str(log.get('value', '')) for log in logs])
if log_type == 'error':
self._logger.error(content)
logged_error = True
self.take_screenshot()
self._save_screencast()
return False
else:
self._logger.info('console log: %s', content)
for log in logs:
if log.get('type', '') == 'string' and log.get('value', '').lower() == 'ok':
# it is possible that some tests returns ok while an error was shown in logs.
# since runbot should always be red in this case, better explicitly fail.
if logged_error:
return False
if 'test successful' in content:
return True
elif log.get('type', '') == 'string' and log.get('value', '').lower().startswith('error'):
self.take_screenshot()
self._save_screencast()
return False
elif res and res.get('method') == 'Page.screencastFrame':
self.screencast_frames.append(res.get('params'))
elif res:
@@ -892,10 +885,10 @@ class HttpCase(TransactionCase):
- eval(code) inside the page
To signal success test do:
console.log('ok')
console.log('test successful')
To signal failure do:
console.log('error')
console.error('test failed')
If neither are done before timeout test fails.
"""