-
Notifications
You must be signed in to change notification settings - Fork 0
Setting up Selenium
Selenium-RC requires the Java Runtime Environment (JRE) version 1.5.0 or higher
sudo gem install SeleniumUnfortunately 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 RC Beta 2:
http://seleniumhq.org/download/
Once you have extracted the download we copy:
selenium-remote-control-1.0-beta-2/selenium-server-1.0-beta-2/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
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>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>Run the Cucumber Selenium example
cucumber examples/selenium/features/“Official Selenium-RC site”:"http://selenium-rc.seleniumhq.org/
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
NOTE – when using this setup, you do not need to start selenium manually. Webrat will spawn a new selenium process and a mongrel process for you.
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:
cucumberTo run your selenium features, you can execute:
cucumber -p selenium