You are previewing Application Testing with Capybara.
O'Reilly logo
Application Testing with Capybara

Book Description

Confidently implement automated tests for web applications using Capybara

  • 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

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.

Table of Contents

  1. Application Testing with Capybara
    1. Table of Contents
    2. Application Testing with Capybara
    3. Credits
    4. About the Author
    5. About the Reviewers
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Your First Scenario with Capybara
      1. Installing Capybara
      2. Preparing your system
        1. Installing gems with RubyGems
        2. Installing gems with Bundler
      3. Installing system libraries
      4. Installing Capybara
        1. Using RubyGems
        2. Using Bundler
      5. Installing Cucumber and Selenium
      6. Cucumber-Rails
      7. Your first scenario – a YouTube search
      8. Summary
    9. 2. Mastering the API
      1. Locating elements with XPath and CSS
        1. Default selector in Capybara
        2. A helping hand with selectors
      2. Navigation
        1. Clicking on links or buttons
      3. Submitting forms
        1. Checkboxes and radio buttons
      4. Finders, scoping, and multiple matches
        1. Multiple matches
        2. Matching strategies
        3. Element visibility
        4. Scoping
      5. Asserting and querying
        1. Matchers and RSpec
        2. Refining finders and matchers
        3. Checking attribute values
      6. Summary
    10. 3. Testing Rails and Sinatra Applications
      1. Understanding the Rack interface
      2. Capybara and Rack::Test
        1. Testing a Sinatra application
          1. Sinatra application file – app.rb
          2. Form template – form.erb
          3. Results template – result.erb
        2. Testing with Rack::Test
      3. Which driver to use and when?
      4. A note on Rails/RSpec and Capybara
      5. Summary
    11. 4. Dealing with Ajax, JavaScript, and Flash
      1. Ajax and asynchronous JavaScript
        1. Capybara and asynchronous JavaScript
        2. Methods that handle asynchronous JavaScript
          1. Finders
          2. Matchers
          3. Gotchas
      2. Flash and HTML5 – black box elements
        1. Flash
        2. Exposing a testable API
        3. Test pages – behold the power!
        4. Testing components "in situ"
      3. Summary
    12. 5. Ninja Topics
      1. Using Capybara outside of Cucumber
        1. Including the modules
        2. Using the session directly
        3. Capybara and popular test frameworks
          1. Cucumber
          2. RSpec
          3. Test::Unit
          4. MiniTest::Spec
      2. Advanced interactions and accessing the driver directly
        1. Using the native method
        2. Accessing driver methods using browser.manage
      3. Advanced driver configuration
      4. The driver ecosystem
        1. Capybara-WebKit
        2. Poltergeist
        3. Capybara-Mechanize
        4. Capybara-Celerity
      5. Summary
    13. Index