diff --git a/client/galaxy/scripts/galaxy.js b/client/galaxy/scripts/galaxy.js index ae306e14687..cbd968e2ecc 100644 --- a/client/galaxy/scripts/galaxy.js +++ b/client/galaxy/scripts/galaxy.js @@ -27,6 +27,8 @@ addLogging(GalaxyApp, "GalaxyApp"); var DEBUGGING_KEY = "galaxy:debug"; var NAMESPACE_KEY = `${DEBUGGING_KEY}:namespaces`; +var FLATTEN_LOG_MESSAGES_KEY = `${DEBUGGING_KEY}:flatten`; + var localDebugging = false; try { localDebugging = localStorage.getItem(DEBUGGING_KEY) == "true"; @@ -137,6 +139,10 @@ GalaxyApp.prototype._initLogger = function _initLogger(loggerOptions) { try { loggerOptions.consoleNamespaceWhitelist = localStorage.getItem(NAMESPACE_KEY).split(","); } catch (storageErr) {} + try { + loggerOptions.consoleFlattenMessages = localStorage.getItem(FLATTEN_LOG_MESSAGES_KEY) == "true"; + } catch (storageErr) {} + console.log(loggerOptions.consoleFlattenMessages); } self.logger = new metricsLogger.MetricsLogger(loggerOptions); diff --git a/client/galaxy/scripts/utils/metrics-logger.js b/client/galaxy/scripts/utils/metrics-logger.js index abe9f09c9ed..a1fb80b1672 100644 --- a/client/galaxy/scripts/utils/metrics-logger.js +++ b/client/galaxy/scripts/utils/metrics-logger.js @@ -68,6 +68,8 @@ MetricsLogger.defaultOptions = { * note: applies only to the console (not the event/metrics log/cache) */ consoleNamespaceWhitelist: null, + /** Force all messages into simple strings. */ + consoleFlattenMessages: false, /** the prefix attached to client-side logs to distinguish them in the metrics db */ clientPrefix: "client.", @@ -283,6 +285,14 @@ MetricsLogger.prototype._delayPost = function _delayPost() { }, self.options.delayPostInMs); }; +function usefulToString(arg) { + var asStr = String(arg); + if (asStr == "[object Object]") { + asStr = JSON.stringify(arg); + } + return asStr; +} + //----------------------------------------------------------------------------- console /** output message to console based on level and consoleLogger type */ MetricsLogger.prototype._emitToConsole = function _emitToConsole(level, namespace, logArguments) { @@ -300,6 +310,9 @@ MetricsLogger.prototype._emitToConsole = function _emitToConsole(level, namespac var args = Array.prototype.slice.call(logArguments, 0); args.unshift(namespace); + if (self.options.consoleFlattenMessages) { + args = [args.map(usefulToString).join(" ")]; + } //TODO: script location and/or source maps? //TODO: branch on navigator.userAgent == AIIEEE - it only has log if (level >= MetricsLogger.METRIC && typeof self.consoleLogger.info === "function") { diff --git a/test/galaxy_selenium/driver_factory.py b/test/galaxy_selenium/driver_factory.py index f232e155448..1e9b729225c 100644 --- a/test/galaxy_selenium/driver_factory.py +++ b/test/galaxy_selenium/driver_factory.py @@ -10,6 +10,9 @@ from selenium.webdriver.common.desired_capabilities import DesiredCapabilities DEFAULT_BROWSER = "auto" +LOGGING_PREFS = { + "browser": "ALL", +} def get_local_driver(browser=DEFAULT_BROWSER): @@ -29,7 +32,7 @@ def get_local_driver(browser=DEFAULT_BROWSER): "PHANTOMJS": webdriver.PhantomJS, } driver_class = driver_to_class[browser] - return driver_class() + return driver_class(desired_capabilities={"loggingPrefs": LOGGING_PREFS}) def get_remote_driver( @@ -42,9 +45,7 @@ def get_remote_driver( browser = "CHROME" assert browser in ["CHROME", "EDGE", "ANDROID", "FIREFOX", "INTERNETEXPLORER", "IPAD", "IPHONE", "OPERA", "PHANTOMJS", "SAFARI"] desired_capabilities = getattr(DesiredCapabilities, browser) - desired_capabilities["loggingPrefs"] = { - "browser": "ALL", - } + desired_capabilities["loggingPrefs"] = LOGGING_PREFS executor = 'http://%s:%s/wd/hub' % (host, port) driver = webdriver.Remote( command_executor=executor, diff --git a/test/selenium_tests/framework.py b/test/selenium_tests/framework.py index 4f83ded97e7..b2d91676f19 100644 --- a/test/selenium_tests/framework.py +++ b/test/selenium_tests/framework.py @@ -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"