Log javascript errors during bok_choy tests

This commit is contained in:
Calen Pennington
2018-04-04 14:19:06 -04:00
parent 79cd02b001
commit d4bb203308
5 changed files with 73 additions and 1 deletions

View File

@@ -49,6 +49,9 @@ update_module_store_settings(
# Needed to enable licensing on video modules
XBLOCK_SETTINGS.update({'VideoDescriptor': {'licensing_enabled': True}})
# Capture the console log via template includes, until webdriver supports log capture again
CAPTURE_CONSOLE_LOG = True
############################ STATIC FILES #############################
# Enable debug so that static assets are served by Django

View File

@@ -41,6 +41,23 @@ from openedx.core.release import RELEASE_LINE
jsi18n_path = "js/i18n/{language}/djangojs.js".format(language=LANGUAGE_CODE)
%>
% if getattr(settings, 'CAPTURE_CONSOLE_LOG', False):
<script type="text/javascript">
var oldOnError = window.onerror;
window.localStorage.setItem('console_log_capture', JSON.stringify([]));
window.onerror = function (message, url, lineno, colno, error) {
if (oldOnError) {
oldOnError.apply(this, arguments);
}
var messages = JSON.parse(window.localStorage.getItem('console_log_capture'));
messages.push([message, url, lineno, colno, (error || {}).stack]);
window.localStorage.setItem('console_log_capture', JSON.stringify(messages));
}
</script>
% endif
<script type="text/javascript" src="${static.url(jsi18n_path)}"></script>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="path_prefix" content="${EDX_ROOT_URL}">

View File

@@ -740,6 +740,39 @@ class AcceptanceTest(WebAppTest):
# Use long messages so that failures show actual and expected values
self.longMessage = True # pylint: disable=invalid-name
def tearDown(self):
try:
self.browser.get('http://{}:{}'.format(
os.environ.get('BOK_CHOY_HOSTNAME', '127.0.0.1'),
os.environ.get('BOK_CHOY_LMS_PORT', 8003),
))
except:
self.browser.get('http://{}:{}'.format(
os.environ.get('BOK_CHOY_HOSTNAME', '127.0.0.1'),
os.environ.get('BOK_CHOY_CMS_PORT', 8031),
))
logs = self.browser.execute_script("return window.localStorage.getItem('console_log_capture');")
if not logs:
return
logs = json.loads(logs)
log_dir = path('test_root') / 'log'
if 'shard' in os.environ:
log_dir /= "shard_{}".format(os.environ["SHARD"])
log_dir.mkdir_p()
with (log_dir / '{}.browser.log'.format(self.id())).open('w') as browser_log:
for (message, url, line_no, col_no, stack) in logs:
browser_log.write(u"{}:{}:{}: {}\n {}\n".format(
url,
line_no,
col_no,
message,
(stack or "").replace('\n', '\n ')
))
super(AcceptanceTest, self).tearDown()
class UniqueCourseTest(AcceptanceTest):
"""

View File

@@ -49,6 +49,9 @@ update_module_store_settings(
default_store=os.environ.get('DEFAULT_STORE', 'draft'),
)
# Capture the console log via template includes, until webdriver supports log capture again
CAPTURE_CONSOLE_LOG = True
############################ STATIC FILES #############################
# Enable debug so that static assets are served by Django

View File

@@ -61,6 +61,22 @@ from pipeline_mako import render_require_js_path_overrides
ie11_fix_path = "js/ie11_find_array.js"
%>
% if getattr(settings, 'CAPTURE_CONSOLE_LOG', False):
<script type="text/javascript">
var oldOnError = window.onerror;
window.localStorage.setItem('console_log_capture', JSON.stringify([]));
window.onerror = function (message, url, lineno, colno, error) {
if (oldOnError) {
oldOnError.apply(this, arguments);
}
var messages = JSON.parse(window.localStorage.getItem('console_log_capture'));
messages.push([message, url, lineno, colno, (error || {}).stack]);
window.localStorage.setItem('console_log_capture', JSON.stringify(messages));
}
</script>
% endif
<script type="text/javascript" src="${static.url(jsi18n_path)}"></script>
<script type="text/javascript" src="${static.url(ie11_fix_path)}"></script>
@@ -167,7 +183,7 @@ from pipeline_mako import render_require_js_path_overrides
% endif
<%include file="/page_banner.html" />
<div class="marketing-hero"><%block name="marketing_hero"></%block></div>
<div class="content-wrapper main-container" id="content">