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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)