From d4bb2033081e14036a13b56649a3b6a9c8d61617 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 4 Apr 2018 14:19:06 -0400 Subject: [PATCH] Log javascript errors during bok_choy tests --- cms/envs/bok_choy.py | 3 +++ cms/templates/base.html | 17 +++++++++++++ common/test/acceptance/tests/helpers.py | 33 +++++++++++++++++++++++++ lms/envs/bok_choy.py | 3 +++ lms/templates/main.html | 18 +++++++++++++- 5 files changed, 73 insertions(+), 1 deletion(-) diff --git a/cms/envs/bok_choy.py b/cms/envs/bok_choy.py index eb6366318d..0c2fdbc99e 100644 --- a/cms/envs/bok_choy.py +++ b/cms/envs/bok_choy.py @@ -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 diff --git a/cms/templates/base.html b/cms/templates/base.html index ccf1a53595..47610d1710 100644 --- a/cms/templates/base.html +++ b/cms/templates/base.html @@ -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): + + % endif + diff --git a/common/test/acceptance/tests/helpers.py b/common/test/acceptance/tests/helpers.py index 99dc3b1c5b..5e4460eced 100644 --- a/common/test/acceptance/tests/helpers.py +++ b/common/test/acceptance/tests/helpers.py @@ -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): """ diff --git a/lms/envs/bok_choy.py b/lms/envs/bok_choy.py index f12920e27f..dc7a44c9a8 100644 --- a/lms/envs/bok_choy.py +++ b/lms/envs/bok_choy.py @@ -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 diff --git a/lms/templates/main.html b/lms/templates/main.html index 6b960ab973..a5429ac903 100644 --- a/lms/templates/main.html +++ b/lms/templates/main.html @@ -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): + + % endif @@ -167,7 +183,7 @@ from pipeline_mako import render_require_js_path_overrides % endif <%include file="/page_banner.html" /> - +
<%block name="marketing_hero">