Capybara-screenshot Show archive.org snapshot can automatically save screenshots and the HTML for failed Capybara tests in Cucumber, RSpec or Minitest.
Requires Capybara-Webkit, Selenium or poltergeist for making screenshots. They're saved into $APPLICATION_ROOT/tmp/capybara
The attached files contain config for cucumber integration and a Then show me a screenshot
step.
If your project uses
Spreewald
Show archive.org snapshot
, you can use its Then show me the page
step instead.
Manually saving a page
Additionally you can trigger the same behavior manually from the test using Capybara::Session#save_and_open_page Show archive.org snapshot and Capybara::Session#save_screenshot Show archive.org snapshot .
Use Rails' built-in screenshot module
If you want to avoid an external gem and use system tests, you can also use Rails' built-in ScreenshotHelper module Show archive.org snapshot available for Rails >= 5.
Including assets in HTML screenshots for prettier presentation
Note
Capybara takes two kinds of screenshots: a regular image and a copy of the HTML. Capybara does not save any assets referenced from that HTML. With the following config the HTML screenshot will reference assets in the same location where your development server usually provides them.
Make sure to add this to config/environments/test.rb
# Do not generate digests for assets URLs.
config.assets.digest = false
and to features/support/capybara.rb
:
# Have HTML screenshot render with assets (while `b rails s` is running)
Capybara.asset_host = 'http://localhost:3000'
You might want to replace localhost
with a fitting unique localhost loopback domain.