Wednesday, January 26, 2011

Cucumber,Capybara & Webrat, Selenium

Cucumber is a BDD tool that provides a language - Given/When/Then syntax for describing "behavior"
The steps in this behavior description maybe implemented as pure Ruby code or in a variety of other DSL's like Capybara or Webrat for acceptance testing web applications. Both Capybara and Webrat are similar - the former has a cleaner/more flexible architecture. They both provide DSL e.g.
visit('/projects')
fill_in('First Name', :with => 'John')
click_link('id-of-link')
Here are reasons why Capybara is better than Webrat from the author himself)
"Webrat is fantastic, and it has done wonders for testing Ruby webapps,
it provides a very slick and elegant DSL for interacting with webapps,
but it also has a couple of problems:
* It is strongly tied to Rails and the Integration Testing built into
Rails
* It doesn't have (comprehensive) support for testing JavaScript
* It is difficult to extend
* There is no driver agnostic test suite to make sure that Selenium
mode for example behaves the same as Rails mode.
* It cannot run different drivers in the same process, so it can't run
one feature under selenium and another in simulation.
All of these pain points led me to tinker around with building a
driver agnostic solution with the following goals:
* Make it dead simple to switch between different drivers
* Support multiple drivers out of the Box
* Provide a comprehensive test suite which can run against any driver
* Make it work with any Rack based framework
* Make it as compatible as possible with the Webrat API
The result of this work is called Capybara and can be found at GitHub
here: http://github.com/jnicklas/capybara
It uses rack-test to simulate a browser instead of Rails' Integration
Testing, which means that interacting with the controller is out (it's
bad practice anyway, imho. It's an integration test after all). I also
intentionally didn't make have_tag and have_text work, since those by
virtue of how they work will never be useful with Selenium, Culerity
or any other browser simulator. Instead there's have_content,
have_xpath and have_css. Other than that it's very similar to Webrat. "

No comments:

Post a Comment