How can I automatically save the html and a screenshot when a test fails using capybara-webkit with Rspec? How can I execute a callback when an RSpec test fails.
Bonus points: how can I avoid getting the following error:
Capybara::Driver::Webkit::WebkitInvalidResponseError
when executing this code:
require 'capybara/util/save_and_open_page'
path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
png = Capybara.save_and_open_page_path + "#{path}.png"
page.driver.render Rails.root.join(png)
I have written a gem Capybara-Screenshot specifically for this, check out https://github.com/mattheworiordan/capybara-screenshot
It will automatically create screen shots on failed RSpec or Cucumber steps.
Capybara provides a function for saving and opening a screenshoot during the testing. You just need to call anywhere in your test:
save_and_open_screenshot
and it will open a picture how the test looks like at that point. No need for any additional gems.
Capybara::save_and_open_screenshot
Found a gist that might help you https://gist.github.com/1156691
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With