Enable galaxy logging during Selenium tests.

- Use localStorage to enable the logs at the start of new connections during tests.
- Add new flatten console logging options in the client to hack around problem recovering multiple argument style logging the client uses with only getting back first argument when using Selenium API (at least with Chrome).
- Break out the browser log into a sort of default and verbose mode (only the latter includes DEBUG and INFO messages).
- Use json.dump with the indent call to get more visually parsable logging messages in the Selenium test failure dump.
This commit is contained in:
John Chilton
2017-11-05 14:37:37 -05:00
parent ed0ac48985
commit a7b32a772d
4 changed files with 42 additions and 5 deletions
+18 -1
View File
@@ -57,6 +57,14 @@ GALAXY_TEST_SELENIUM_USER_PASSWORD = os.environ.get("GALAXY_TEST_SELENIUM_USER_P
GALAXY_TEST_SELENIUM_ADMIN_USER_EMAIL = os.environ.get("GALAXY_TEST_SELENIUM_ADMIN_USER_EMAIL", DEFAULT_ADMIN_USER)
GALAXY_TEST_SELENIUM_ADMIN_USER_PASSWORD = os.environ.get("GALAXY_TEST_SELENIUM_ADMIN_USER_PASSWORD", DEFAULT_ADMIN_PASSWORD)
# JS code to execute in Galaxy JS console to setup localStorage of session for logging and
# logging "flatten" messages because it seems Selenium (with Chrome at least) only grabs
# the first argument to console.XXX when recovering the browser log.
SETUP_LOGGING_JS = '''
window.localStorage && window.localStorage.setItem("galaxy:debug", true);
window.localStorage && window.localStorage.setItem("galaxy:debug:flatten", true);
'''
try:
from nose.tools import nottest
except ImportError:
@@ -107,8 +115,11 @@ def dump_test_information(self, name_prefix):
snapshot.write_to_error_directory(write_file)
for log_type in ["browser", "driver"]:
full_log = self.driver.get_log(log_type)
trimmed_log = [l for l in full_log if l["level"] not in ["DEBUG", "INFO"]]
try:
write_file("%s.log.json" % log_type, json.dumps(self.driver.get_log(log_type)))
write_file("%s.log.json" % log_type, json.dumps(trimmed_log, indent=True))
write_file("%s.log.verbose.json" % log_type, json.dumps(full_log, indent=True))
except Exception:
continue
iframes = self.driver.find_elements_by_css_selector("iframe")
@@ -227,9 +238,15 @@ class SeleniumTestCase(FunctionalTestCase, NavigatesGalaxy, UsesApiTestCaseMixin
# to increase this.
self.driver.set_window_size(1280, 900)
self._setup_galaxy_logging()
if self.ensure_registered:
self.login()
def _setup_galaxy_logging(self):
self.home()
self.driver.execute_script(SETUP_LOGGING_JS)
def login(self):
if GALAXY_TEST_SELENIUM_USER_EMAIL:
assert GALAXY_TEST_SELENIUM_USER_PASSWORD, "If GALAXY_TEST_SELENIUM_USER_EMAIL is set, a password must be set also with GALAXY_TEST_SELENIUM_USER_PASSWORD"