In episode #136 of Railscasts, Ryan Bates showed us how to quickly turn a regular form into one that is submitted with Ajax.
In this episode you can see how to write a feature to test this functionality using Selenium.
Cucumber is great for Rails integration testing because it exercises the entire Rails stack, starting from the route mapper, through the controller, the models, right down to the database.
To achieve this, it uses Webrat which accesses your application very close to how a browser would do it.
Webrat however is not a browser. When you ask it to fetch a URL from your application, it actually takes a shortcut by instantiating your controllers and passing them a mock HTTP request.
This method however, does not let you test the client-side AJAX functionality of your application.
One solution, shown in this episode, is to use a full featured browser such as Firefox with a well known plugin: Selenium.
Learn how to:
- start with a Webrat feature and turn it into a Selenium feature;
- configure Cucumber with multiple profiles, to separate features using Selenium;
- emulate transactional fixtures using database_cleaner;
- create a new Rails environment for Selenium;
- Write Selenium steps for matching DOM elements.