If you've built a complicated application and you want to make sure it works, you perform acceptance testing. This three-part article series will show you how to automate the process. It is excerpted from chapter 11 of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).
In this chapter, you will learn how to automate acceptance tests. Acceptance tests are important, since they prove that the system works according to the requirements.
Throughout this book, George has been performing acceptance testing quite haphazardly by randomly testing that the user stories we have implemented work as he intended. This is better than no acceptance tests at all, but since we're building an e-commerce site, we want to be absolutely sure that everything works all the time. We don't want to lose a customer by providing a service that doesn't work as expected, and George doesn't have the money to hire a dedicated tester. This is where Seleniuman-- open source testing tool originally developed as an in-house project at ThoughtWorks--comes in handy.
With Selenium and the Selenium on Rails plugin, you can automate acceptance tests that otherwise would be performed manually, or more likely, not at all. You can run the automated acceptance tests when, for example, you refactor code or release a new version. This raises your comfort level by giving you immediate feedback when something breaks.
Selenium on Rails (http://www.openqa.org/selenium-on-rails), a plugin developed by Jonas Bengtsson, integrates Selenium into the Rails framework. The plugin provides many features to simplify the use of Selenium with Rails. For example, it does the following:
Creates test suites automatically from tests that are located in the same directory. For example, storing a test in test/selenium/authentication/test_login.sel would automatically make the test (test_login.sel) belong to the authentication test suite.
Deploys Selenium to the test environment automatically. (Selenium is not deployed to the development or production environments by default.)
Allows you to write Selenium tests in ERB, Selenese, or RSelenese, rather than just HTML.
Lets you place the Selenium files in a directory other than /public. Selenium can be located in /vendor/selenium or the RubyGems repository.
Allows for the use of fixtures in Selenium tests and clearing sessions. Fixtures are run by accessing the URL /selenium/setup from acceptance tests.