Application Testing with Capybara

Application Testing with Capybara
eBook: $19.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $53.98    Print cover: $33.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Learn everything to become super productive with this highly acclaimed test automation library
  • Using some advanced features, turn yourself into a Capybara ninja!
  • Packed with practical examples and easy-to-follow sample mark-up and test code

Book Details

Language : English
Paperback : 104 pages [ 235mm x 191mm ]
Release Date : September 2013
ISBN : 1783281251
ISBN 13 : 9781783281251
Author(s) : Matthew Robbins
Topics and Technologies : All Books, App Testing, Application Development, Open Source

Table of Contents

Chapter 1: Your First Scenario with Capybara
Chapter 2: Mastering the API
Chapter 3: Testing Rails and Sinatra Applications
Chapter 4: Dealing with Ajax, JavaScript, and Flash
Chapter 5: Ninja Topics
  • Chapter 1: Your First Scenario with Capybara
    • Installing Capybara
    • Preparing your system
      • Installing gems with RubyGems
      • Installing gems with Bundler
    • Installing system libraries
    • Installing Capybara
      • Using RubyGems
      • Using Bundler
    • Installing Cucumber and Selenium
    • Cucumber-Rails
    • Your first scenario – a YouTube search
    • Summary
    • Chapter 2: Mastering the API
      • Locating elements with XPath and CSS
        • Default selector in Capybara
        • A helping hand with selectors
      • Navigation
        • Clicking on links or buttons
      • Submitting forms
        • Checkboxes and radio buttons
      • Finders, scoping, and multiple matches
        • Multiple matches
        • Matching strategies
        • Element visibility
        • Scoping
      • Asserting and querying
        • Matchers and RSpec
        • Refining finders and matchers
        • Checking attribute values
      • Summary
      • Chapter 3: Testing Rails and Sinatra Applications
        • Understanding the Rack interface
        • Capybara and Rack::Test
          • Testing a Sinatra application
            • Sinatra application file – app.rb
            • Form template – form.erb
            • Results template – result.erb
          • Testing with Rack::Test
        • Which driver to use and when?
        • A note on Rails/RSpec and Capybara
        • Summary
        • Chapter 4: Dealing with Ajax, JavaScript, and Flash
          • Ajax and asynchronous JavaScript
            • Capybara and asynchronous JavaScript
            • Methods that handle asynchronous JavaScript
              • Finders
              • Matchers
              • Gotchas
          • Flash and HTML5 – black box elements
            • Flash
            • Exposing a testable API
            • Test pages – behold the power!
            • Testing components "in situ"
          • Summary
          • Chapter 5: Ninja Topics
            • Using Capybara outside of Cucumber
              • Including the modules
              • Using the session directly
              • Capybara and popular test frameworks
                • Cucumber
                • RSpec
                • Test::Unit
                • MiniTest::Spec
            • Advanced interactions and accessing the driver directly
              • Using the native method
              • Accessing driver methods using browser.manage
            • Advanced driver configuration
            • The driver ecosystem
              • Capybara-WebKit
              • Poltergeist
              • Capybara-Mechanize
              • Capybara-Celerity
            • Summary

            Matthew Robbins

            Matthew Robbins is an experienced developer in test, having spent many years wrestling with commercially available test automation tools. He has spent the last five years immersed in developing robust test automation frameworks using open source tools. He worked extensively with the BBC developing test automation frameworks and tools across their web platform and continues to work in the media industry for other high-profile broadcasters. Aside from test automation, he is passionate about becoming more productive in Vim and learning about web browser internals. He also regularly blogs at
            Sorry, we don't have any reviews for this title yet.

            Code Downloads

            Download the code and support files for this book.

            Submit Errata

            Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.

            Sample chapters

            You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

            Frequently bought together

            Application Testing with Capybara +    Node Web Development - Second Edition =
            50% Off
            the second eBook
            Price for both: $32.95

            Buy both these recommended eBooks together and get 50% off the cheapest eBook.

            What you will learn from this book

            • Install and configure Capybara
            • Use Capybara and Cucumber to test scenarios
            • Exploit Capybara’s API for interacting with web pages
            • Employ Capybara to test Rack applications implemented using Rails or Sinatra
            • Handle asynchronous JavaScript
            • Apply Capybara to test “black box” components such as Flash or HTML5 Canvas, Audio, and Video
            • Practise Capybara outside Cucumber in bespoke frameworks
            • Use Capybara with popular Ruby test frameworks
            • Explore advanced driver configuration
            • Work with alternative drivers such as Capybara-Webkit and Capybara-Mechanize

            In Detail

            Everybody understands why implementing automated tests is important but at the same time developing them can be costly and time consuming, and tests can be also be fragile and prone to false positives. By using Capybara, you can develop robust tests quickly and run them in multiple drivers ensuring greater re-use; Capybara’s API also extends the human readable style made popular by frameworks such as Cucumber and RSpec.

            "Application Testing with Capybara" takes you from installing the gem to getting up and running with a YouTube search scenario within the first two chapters. We then look deeper into the API, using Rack-Test for applications built with Rails or Sinatra and see how to test handle Asynchronous JavaScript and “black box” components such as Flash. Finally, we consider some advanced topics such as looking at alternatives to Selenium and accessing the native driver directly.

            This book takes you from the basics of installing Capybara, through its API and onto advanced topics. You will learn how to use Capybara’s extensive API to interact with your application, covering topics such as navigation, filling in forms, and querying your page for expected content. Beyond this we will consider why Capybara is so well suited to testing applications written in frameworks such as Rails and Sinatra. We will look at strategies for validating seemingly “untestable” components such as HTML5 or Flash by building out a testable API. Finally we will turn you into a Capybara ninja by covering advanced topics such as accessing functionality in the base driver, advanced driver configuration, and alternative flavours of drivers outside Selenium and Rack-Test.


            Start performing integration testing with Capybara immediately. This book will get you up and running quickly and assumes no knowledge or experience of the technology.

            Who this book is for

            This book is for developers and testers who have had some exposure to Ruby but who want to know how to test their applications using Capybara and its compatible drivers, such as Selenium-Webdriver and Rack-Test. The examples are deliberately kept simple and example HTML mark-up is always included so that you can copy the examples to practice and experiment on your own machine.

            Code Download and Errata
            Packt Anytime, Anywhere
            Register Books
            Print Upgrades
            eBook Downloads
            Video Support
            Contact Us
            Awards Voting Nominations Previous Winners
            Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
            Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software