Skip to content

Instantly share code, notes, and snippets.

@osulyanov
Created April 14, 2014 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osulyanov/10609515 to your computer and use it in GitHub Desktop.
Save osulyanov/10609515 to your computer and use it in GitHub Desktop.
Capybara auto-saving screenshots on test failures
RSpec.configure do |config|
config.after(:each) do
if example.exception && example.metadata[:js]
meta = example.metadata
filename = File.basename(meta[:file_path])
line_number = meta[:line_number]
screenshot_name = "screenshot-#{filename}-#{line_number}.png"
screenshot_path = "#{Rails.root.join("tmp")}/#{screenshot_name}"
page.save_screenshot(screenshot_path)
puts meta[:full_description] + "\n Screenshot: #{screenshot_path}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment