Read more

Taking screenshots in Capybara

Thomas Klemm
January 13, 2015Software engineer

Capybara-screenshot Show archive.org snapshot can automatically save screenshots and the HTML for failed Capybara tests in Cucumber, RSpec or Minitest.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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.

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.

Posted by Thomas Klemm to makandra dev (2015-01-13 11:35)