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 UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
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)