views:

99

answers:

1

Im reading The Rspec book and in that book, they are using webrat with selenium.

I wonder if its possible to use selenium directly for integration tests in Rails instead of using it through webrat?

What are the pros and cons with each way?

+1  A: 

It is most definitely possible to use Selenium by itself. I recommend installing the Selenium IDE plugin for Firefox. This gives you an easy scripting layer to automate clicks and that sort of thing. By integrating Selenium with Rails, you can execute integration tests from the command line, which is nice for a number of reasons: other developers on your team can run them more easily, you can run the same tests against multiple browsers more easily, and you can run the tests from a continuous integration server (that can launch a web browser).

We use Cucumber with Capybara for our integration tests. Webrat does not support JavaScript, so if you click a link that has a click event handler for example, the handler won't fire. Capybara knows Javascript so will fire the event handler. Selenium would let you do this as well, but we already use Cucumber and I prefer Cucumber+Capybara tests to Selenium because it is more integrated and the tests are easier to maintain.

Andy Atkinson
But is it possible to use Cucumber + Selenium without Capybara? What are the pros and cons here?
never_had_a_name
Yes. Capybara and Selenium serve similar purposes, you'd use one or the other. Your Cucumber scripts could "drive" Selenium to launch a web browser and start clicking things, or they could drive Capybara to do the same.
Andy Atkinson