The following is the result of having to setup cucumber to use webrat and selenium twice from scratch and not finding a very good resource for doing so. I hope this can help someone else. Corrections and feedback are welcome.
Install selenium-client version 1.2.16
$ gem install selenium-client --version=1.2.16
Generate cucumber environment
$ ./script/generate cucumber
Use can use my cucumber_setup rails generator. It’s on github at http://github.com/kevincolyar/rails_generators and run:
$ ./script/generate cucumber_setup
and you’re done.
Otherwise, here’s how you can setup your rails environment to use both webrat and selenium with rails from scratch.
Create a cucumber.yml file in the root of your rails project containing the following:
1 default: -r features/support -r features/environments/plain.rb -r features/step_definitions features/plain
2 selenium: -r features/support -r features/environments/enhanced.rb -r features/step_definitions features/enhanced
3 autotest: -r features/support -r features/environments/plain.rb -r features/step_definitions --color --format pretty --tags ~@selenium
4 autotest-all: -r features/support -r features/environments/plain.rb -r features/step_definitions --color --format progress --tags ~@selenium
Create the following directories:
$ mkdir features/environments features/plain features/enhanced
Create features/environments/plain.rb containing the following:
2 #Cucumber::Rails.bypass_rescue # Comment out this line if you want Rails own error handling
4 Webrat.configure do |config|
5 config.mode = :rails
7 # (e.g. rescue_action_in_public / rescue_responses / rescue_from)
Create features/environments/enhanced.rb containing the following:
2 Webrat.configure do |config|
3 config.mode = :selenium
4 # Selenium defaults to using the selenium environment. Use the following to override this.
5 # config.application_environment = :test
8 # this is necessary to have webrat "wait_for" the response body to be available
9 # when writing steps that match against the response body returned by selenium
12 Before do
13 # truncate your tables here, since you can't use transactional fixtures*
$ cd /Applications/Firefox.app/Contents/MacOS
$ sudo mv libsqlite3.dylib _libsqlite3.dylib
If anyone knows a better fix for this please let me know.
Now just place your webrat stories in features/plain and your selenium stories features/enhanced
To run your webrat stories, simply run:
To run your selenium stories, run:
$ cucumber -p selenium