From 43f2e7f062fa33d78de8725ee1e3f3a9107dd08e Mon Sep 17 00:00:00 2001 From: Peter Belanyi Date: Fri, 25 Apr 2014 16:14:24 +0200 Subject: [PATCH] Improve error reporting In case of errors, the selenuim testcase extracts the test name, error message and source of the error from the qunit page and logs them, so that it's easier to locate the issue. Also added 'from __future__ import absolute_import' to avoid issues with importing the selenium library from the script named selenium.py Change-Id: I040d147ad9c78fe48080b6a01ff1b4d89d6e9c3e --- tuskar_ui/test/selenium.py | 27 +++++++++++++++++++++++++-- tuskar_ui/test/settings.py | 5 +++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/tuskar_ui/test/selenium.py b/tuskar_ui/test/selenium.py index d23762429..2eebd8cae 100644 --- a/tuskar_ui/test/selenium.py +++ b/tuskar_ui/test/selenium.py @@ -14,7 +14,12 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import absolute_import + +import logging + from horizon.test import helpers as test +from selenium.common import exceptions as selenium_exceptions class BrowserTests(test.SeleniumTestCase): @@ -28,5 +33,23 @@ class BrowserTests(test.SeleniumTestCase): return "Tests completed" in text wait.until(qunit_done) - failed = self.selenium.find_element_by_class_name("failed") - self.assertEqual(int(failed.text), 0) + + failed_elem = self.selenium.find_element_by_class_name("failed") + failed = int(failed_elem.text) + if failed: + self.log_failure_messages() + self.assertEqual(failed, 0) + + def log_failure_messages(self): + logger = logging.getLogger('selenium') + logger.error("Errors found during qunit test:") + fail_elems = self.selenium.find_elements_by_class_name("fail") + for elem in fail_elems: + try: + module = elem.find_element_by_class_name("module-name").text + except selenium_exceptions.NoSuchElementException: + continue + message = elem.find_element_by_class_name("test-message").text + source = elem.find_element_by_tag_name("pre").text + logger.error("Module: %s, message: %s, source: %s" % ( + module, message, source)) diff --git a/tuskar_ui/test/settings.py b/tuskar_ui/test/settings.py index 4fe56457c..29c1e8779 100644 --- a/tuskar_ui/test/settings.py +++ b/tuskar_ui/test/settings.py @@ -121,6 +121,11 @@ LOGGING['loggers']['openstack_dashboard'] = { 'propagate': False, } +LOGGING['loggers']['selenium'] = { + 'handlers': ['test'], + 'propagate': False, +} + SECURITY_GROUP_RULES = { 'all_tcp': { 'name': 'ALL TCP',