Screen shots - feature request #133

mattheworiordan opened this Issue Aug 17, 2011 · 14 comments


None yet
4 participants

Joel developed a screenshot gem a long time ago that worked with Webrat but generated screen shots when an exception was thrown. Hugely useful when you're using headless browsers. Unfortunately it does not look like it's maintained and it's not compatible with Capybara.

Is this something that Capybara Webkit could so somehow?


tristandunn commented Aug 17, 2011

I'm fairly sure this is already supported. See here and here.


mike-burns commented Aug 17, 2011

That's right, it was done in this commit: 1787324

mike-burns closed this Aug 17, 2011

Thanks Mike and Tristan

I should have spotted that.

BTW. If anyone wants to have automatic screen shots created on a Cucumber feature failure, then check out


mike-burns commented Aug 23, 2011

That's handy. Is it possible for you to either make a gem or a pull request for that auto-screenshotting stuff? It'd be nice to either add like gem "capybara-autoscreenshot" to my Gemfile and have that just work (this could potentially work with Selenium, too), or add require "capybara-webkit/autoscreenshot" to my features/support/webkit.rb and have that just work.

Ok, I'll work something up in the next week or so when I am back home.

Sorry for the stupidly long time to do this, but I've built a simple Gem to do screenshots for Capybara Webkit on scenario failure, and it also saves an HTML file of the current page regardless of which Capybara driver you are using. However, I am experiencing a problem I can't see overcome which I'm hoping perhaps you could help with (on the off change).

I have a very simple world.rb file which access page.body and saves the contents out. The problem is that when the Gem access page.body, page.body is empty and simply contains: `


I am including world.rb in the gem's lib root file, so I can't really see what I am doing wrong.

Strangely, if I put an after block into my sample Rails app env.js file accessing page.body has the correct HTML, so it seems that calling After { my code } in the Gem is being executed once the page has been released.

I realise you may not have the time / inclination to help, but if you do spot something obvious I would appreciate the help.

The gem code is at, and the gem is installed at The sample Rails app which you can use to quickly recreate this issue by simply running cucumber is at

Thanks in advance if you can help. It would be great to release this ridiculously simple bit of code out as a Gem as I find it extremely useful when trying to debug cucumber issues.


Hi Mike

Any ideas why my gem is not working. Quite frustrating for me as I'm at a loose end here and would love to release this as a gem for others if possible.



mike-burns commented Oct 19, 2011

Hi Matt, not sure offhand, but hopefully one of the main capybara-webkit devs will know more.


jferris commented Oct 19, 2011

Hey Matt,

Cucumber executes After hooks in the opposite order in which they were defined:

Can you make sure that your After hook is registered after capybara's?


Well that's what I'm unclear how to do unfortunately. I have marked my Gem as dependent on the capybara gem, so I expect it to be executed after the capybara gem, however it's clearly not. If you take a look at you will see that I call the After hook in the lib definition. Do you know how I can get this to execute after capybara has executed it's After hook?


jferris commented Oct 20, 2011

Declaring capybara as a dependency will ensure that capybara is activated first (meaning that its libraries are added to the load path, etc), but the source files won't be required until the application requires them directly or uses Bundler.require. This process can be confusing in a Rails app, since there's railties, bundler, and ActiveSupport's missing dependency loading all working at the same time.

If you need to make sure that your hook is loaded after capybara's, make sure to require whatever files you depend on. In your case, I think you need to require capybara/cucumber. That file may also have dependencies you need to load first.

Ok, thanks for the pointer. I'll play around with this and see what I can do.

Thanks jferris, brilliant bit of advice, it's all working now and released at and

mike-burns, FYI, the gem is now working for those who want automatic screen shots on failure for Capybara.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment