Giter Club home page Giter Club logo

capybara-screenshot's Introduction

capybara-screenshot gem

Using this gem, whenever a Capybara test in Cucumber, Rspec or Minitest fails, the HTML for the failed page and a screenshot (when using capybara-webkit or Selenium) is saved into $APPLICATION_ROOT/tmp/capybara.

This is a huge help when trying to diagnose a problem in your failing steps as you can view the source code and potentially how the page looked at the time of the failure.

Usage

gem install capybara-screenshot

or update your Gemfile to include:

group :test do
  gem 'capybara-screenshot'
end

That's it!

If you require more control, you can generate the screenshot on demand rather than on failure. This is useful if the failure occurs at a point where the screen shot is not as useful for debugging a rendering problem.

In Cucumber,

screen_shot_and_save_page

Or for screenshot only, with image automatically opened

screen_shot_and_open_image

Or anywhere, including specs and tests

Capybara::Screenshot.screen_shot_and_save_page

Capybara::Screenshot.screen_shot_and_open_image

This can be more useful if you disable the auto-generate on failure feature with the following config

Capybara::Screenshot.autosave_on_failure = false

Example application

A simple Rails 3.1 example application has been set up at https://github.com/mattheworiordan/capybara-screenshot-test-rails-3.1 Git clone the app, and then run Cucumber rake cucumber, RSpec rspec spec/**/*_spec.rb and Minitest rake test and expect intentional failures. Now check the $APPLICATION_ROOT/tmp/capybara folder for the automatic screen shots generated from failed tests.

Repository

Please fork, submit patches or feedback at https://github.com/mattheworiordan/capybara-screenshot

The gem details on RubyGems.org can be found at https://rubygems.org/gems/capybara-screenshot

About

This gem was written by Matthew O'Riordan

License

Copyright © 2012 Matthew O'Riordan, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.

capybara-screenshot's People

Contributors

adzap avatar mattheworiordan avatar hlascelles avatar rb2k avatar wokkaflokka avatar felipecsl avatar nashby avatar

Watchers

Tomas Korcak avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.