Skip to content

Instantly share code, notes, and snippets.

@piotrze
Last active February 24, 2016 08:09
Show Gist options
  • Save piotrze/c9ef67eac23a797d9ee1 to your computer and use it in GitHub Desktop.
Save piotrze/c9ef67eac23a797d9ee1 to your computer and use it in GitHub Desktop.
Save screenshot on failed integration tests with capybara.
# test/test_helper.rb
class ActionDispatch::IntegrationTest
def after_teardown
if !passed?
timestamp = "#{Time.zone.now.strftime('%Y-%m-%d-%H:%M:%S')}"
screenshot_name = "screenshot-#{timestamp}.png"
# Handle CircleCi too
screenshot_path = "#{ENV.fetch('CIRCLE_ARTIFACTS', Rails.root.join('tmp/capybara'))}/#{screenshot_name}"
page.save_screenshot(screenshot_path)
end
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment