@after.each_scenario
def capture_console_log(scenario):
 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')

@ after . each_scenario def capture_console_log ( scenario ) : 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' )
save the console log to help with debugging .