Selenium

Using a Seperate Browser for Selenium with Cucumber

December 30th, 2009 0 Comments

If you’re using Selenium with Cucumber on a Mac you probably know that Firefox 3.5.3 is that latest version that works with Selenium. I was getting fed up with not being able to update to the latest version of Firefox so here’s what I did. Simply install Firefox 3.5.3 (the latest Selenium compatible browser at the time of this writting) and name it /Applications/Firefox-3.5.3.app

This will be the Firefox installation Selenium will use and now you’re free to upgrade your /Applications/Firefox.app install.

Now add the following code to your RAILS_ROOT/features/environments/selenium.rb file.

Webrat.configure do |config|

config.mode = :selenium

# Selenium defaults to using the selenium environment. Use the following to override this.

config.application_environment = :test

config.selenium_browser_key = *firefox /Applications/Firefox-3.5.3.app/Contents/MacOS/firefox-bin

end

Don’t forget to do this hack:

$ cd /Applications/Firefox-3.5.3.app/Contents/MacOS
$ mv libsqlite3.dylib _libsqlite3.dylib

For more help setting up Cucumber and Selenium, check my other post Setting Up Cucumber to Use Webrat and Selenium with Rails.

Setting Up Cucumber to Use Webrat and Selenium with Rails

December 8th, 2009 0 Comments

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

Cucumber Setup:

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
5

Create the following directories:

$ mkdir features/environments features/plain features/enhanced

Create features/environments/plain.rb containing the following:

1 #Cucumber::Rails.use_transactional_fixtures
2 #Cucumber::Rails.bypass_rescue # Comment out this line if you want Rails own error handling
3
4 Webrat.configure do |config|
5   config.mode = :rails
6 end
7 # (e.g. rescue_action_in_public / rescue_responses / rescue_from)

Create features/environments/enhanced.rb containing the following:

1
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
6 end
7
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
10 World(Webrat::Selenium::Matchers)
11
12 Before do
13 # truncate your tables here, since you can't use transactional fixtures*
14 end

Firefox hack:
$ cd /Applications/Firefox.app/Contents/MacOS
$ sudo mv libsqlite3.dylib _libsqlite3.dylib

If anyone knows a better fix for this please let me know.

Running Cucumber:

Now just place your webrat stories in features/plain and your selenium stories features/enhanced

To run your webrat stories, simply run:
$ cucumber

To run your selenium stories, run:
$ cucumber -p selenium