Skip to content

Instantly share code, notes, and snippets.

@ChengLong
Last active March 19, 2016 16:50
Show Gist options
  • Save ChengLong/b92d538b64032174b0e1 to your computer and use it in GitHub Desktop.
Save ChengLong/b92d538b64032174b0e1 to your computer and use it in GitHub Desktop.
Automatically save a screenshot when any scenario fails

To save a screenshot automatically when any scenario fails, add the following in features/support/env.rb

After do |scenario|
  if scenario.failed?
    timestamp = "#{Time.zone.now.strftime('%Y-%m-%d-%H:%M:%S')}"
    screenshot_name = "screenshot-#{scenario.name.parameterize.underscore}-#{timestamp}.png"
    screenshot_path = "#{Rails.root.join('tmp/capybara')}/#{screenshot_name}"
    Capybara.page.save_screenshot(screenshot_path)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment