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
+6
View File
@@ -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);
@@ -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") {
+5 -4
View File
@@ -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,
+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"