@after.each_scenario
def screenshot_on_error(scenario):
 if scenario.failed:
  try:
   output_dir = '{}/log'.format(settings.TEST_ROOT)
   image_name = '{}/{}.png'.format(output_dir, scenario.name.replace(' ', '_'))
   world.browser.driver.save_screenshot(image_name)
  except WebDriverException:
   LOGGER.error('Could not capture a screenshot')

@ after . each_scenario def screenshot_on_error ( scenario ) : if scenario . failed : try : output_dir = '{}/log' . format ( settings . TEST_ROOT ) image_name = '{}/{}.png' . format ( output_dir , scenario . name . replace ( ' ' , '_' ) ) world . browser . driver . save_screenshot ( image_name ) except WebDriverException : LOGGER . error ( 'Could not capture a screenshot' )
save a screenshot to help with debugging .