Merge pull request #4638 from edx/zoldak/lettuce-log-js-console
Capture console log on lettuce test failure
This commit is contained in:
@@ -17,7 +17,6 @@ from base64 import encodestring
|
||||
from json import dumps
|
||||
|
||||
import xmodule.modulestore.django
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.contentstore.django import _CONTENTSTORE
|
||||
|
||||
# There is an import issue when using django-staticfiles with lettuce
|
||||
@@ -94,6 +93,14 @@ def initial_setup(server):
|
||||
if world.LETTUCE_SELENIUM_CLIENT == 'local':
|
||||
browser_driver = getattr(settings, 'LETTUCE_BROWSER', 'chrome')
|
||||
|
||||
if browser_driver == 'chrome':
|
||||
desired_capabilities = DesiredCapabilities.CHROME
|
||||
desired_capabilities['loggingPrefs'] = { 'browser':'ALL' }
|
||||
elif browser_driver == 'firefox':
|
||||
desired_capabilities = DesiredCapabilities.FIREFOX
|
||||
else:
|
||||
desired_capabilities = {}
|
||||
|
||||
# There is an issue with ChromeDriver2 r195627 on Ubuntu
|
||||
# in which we sometimes get an invalid browser session.
|
||||
# This is a work-around to ensure that we get a valid session.
|
||||
@@ -106,7 +113,7 @@ def initial_setup(server):
|
||||
# the browser session is invalid, this will
|
||||
# raise a WebDriverException
|
||||
try:
|
||||
world.browser = Browser(browser_driver)
|
||||
world.browser = Browser(browser_driver, desired_capabilities=desired_capabilities)
|
||||
world.browser.driver.set_script_timeout(GLOBAL_SCRIPT_TIMEOUT)
|
||||
world.visit('/')
|
||||
|
||||
@@ -221,6 +228,25 @@ def screenshot_on_error(scenario):
|
||||
LOGGER.error('Could not capture a screenshot')
|
||||
|
||||
|
||||
@after.each_scenario
|
||||
def capture_console_log(scenario):
|
||||
"""
|
||||
Save the console log to help with debugging.
|
||||
"""
|
||||
if scenario.failed:
|
||||
log = world.browser.driver.get_log('browser')
|
||||
try:
|
||||
output_dir = '{}/log'.format(settings.TEST_ROOT)
|
||||
file_name = '{}/{}.log'.format(output_dir, scenario.name.replace(' ', '_'))
|
||||
|
||||
with open (file_name, 'w') as output_file:
|
||||
for line in log:
|
||||
output_file.write("{}{}".format(dumps(line), '\n'))
|
||||
|
||||
except WebDriverException:
|
||||
LOGGER.error('Could not capture the console log')
|
||||
|
||||
|
||||
def capture_screenshot_for_step(step, when):
|
||||
"""
|
||||
Useful method for debugging acceptance tests that are run in Vagrant.
|
||||
|
||||
Reference in New Issue
Block a user