Skip to content
This repository was archived by the owner on Nov 16, 2018. It is now read-only.

Setting up Selenium

zilkey edited this page Aug 13, 2010 · 38 revisions

Pre-requisites

Selenium-RC requires the Java Runtime Environment (JRE) version 1.5.0 or higher

Step 1: Install the Selenium gem

sudo gem install Selenium

Step 2: Install Selenium-remote

Unfortunately the jar that the Selenium gem (version 1.1.14) comes with does not work with Firefox 3. So we have to get the latest jar from the Selenium-RC site:

Download the Selenium nightly build:

http://selenium-rc.seleniumhq.org/download.html

Once you have extracted the download we copy:

selenium-remote-control-1.0-SNAPSHOT/selenium-server-1.0-SNAPSHOT/selenium-server.jar

Over the jar that was installed with the Selenium gem:

GEM_INSTALL_DIR/Selenium-1.1.14/lib/selenium/openqa/selenium-server.jar.txt

Step 3: Ubuntu fix (skip if you’re not using Ubuntu)

There is a bug with Selenium and Firefox 3 where Selenium cannot find: firefox-bin

To solve this we create a sym link:

sudo ln -s /usr/lib/firefox-3.0.4/firefox /usr/bin/firefox-bin</pre>

Step 4: Starting Selenium

The Selenium gem installs a script which allows us to get Selenium-RC running

selenium</pre>
OR
you can run the jar directly
java -jar selenium-server.jar.txt</pre>

Step 5: Run the cucumber example

Run the Cucumber Selenium example

cucumber examples/selenium/features/

Useful links

“Official Selenium-RC site”:"http://selenium-rc.seleniumhq.org/

Selenium gem at rubyforge

Setting up Cucumber with a profile for plain HTML and a profile for Selenium

Many apps have features that don’t require javascript to work, and running them all in selenium makes things slow. Since webrat steps support selenium out of the box, you can reuse almost all of your standard step definitions for selenium as well. Here’s a recipe for how you can:

  • Run your non-selenium features with transactional fixtures and standard webrat steps
  • Run your entire suite (html and javascript) features with selenium, without transactional fixtures
  • Reuse all (or almost all) or your step definitions between selenium and non-selenium runners

First, setup a directory structure like the following:

features/
|-- enhanced
|   `-- ajaxy.feature
|-- plain
|   `-- non_ajaxy.feature
|-- step_definitions
|   `-- webrat_steps.rb
`-- support
    |-- enhanced.rb
    |-- env.rb
    `-- plain.rb

Create a cucumber.yml file with 2 profiles:

default: -r features/support/env.rb -r features/support/plain.rb -r features/step_definitions features/plain
selenium: -r features/support/env.rb -r features/support/enhanced.rb -r features/step_definitions features/enhanced features/plain

In env.rb, turn on all webrat features:

ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/rails/world'
require 'cucumber/formatters/unicode'
require 'webrat/rails'
require 'cucumber/rails/rspec'

In enhanced.rb, set up the selenium-specific files:

require "webrat/selenium"
World do
  Webrat::Selenium::Rails::World.new
end

Before do
  # truncate your tables here, since you can't use transactional fixtures
end

In plain.rb, set up the standard webrat features:

# truncate your tables here if you are using the same database as selenium, since selenium doesn't use transactional fixtures
Cucumber::Rails.use_transactional_fixtures

To run your regular features, you can execute:

cucumber

To run your selenium features, you can execute:

cucumber -p selenium

Clone this wiki locally