I'm using Selenium with rspec on my project and generate code from a custom formatter for Selenium IDE.
There is many selenium for rails but i success using Selenium-RC http://seleniumhq.org/download/ , so download to your pc.
Here are my steps:
- Unzip and run> java -jar selenium-server.jar
- Open selenium-client-ruby, read the doc, follow it you will get success!
- gem install rspec, rspec-rails version 1.2.6 (it not, you need to comment version restrict of selenium-client source code)
- gem install selenium-client
- Open Selenium-IDE (Firefox of course), Open Options -> Options -> Formats
- Click Add, and paste this code in http://www.techdarkside.com/rspec%5Fexport.txt
Now, You just export spec to your spec folder for me, I use spec/features/xxxx_spec.rb see code below.
Very similar approach can find at here
For webrat+cucumber, the latest Rspec book will give all you need. (They don't have selenium + cucumber chapter finish yet)
example
require 'rubygems'
gem "rspec", "=1.2.6"
gem "selenium-client", ">=1.2.15"
require "selenium/client"
require "selenium/rspec/spec_helper"
describe "Google Search" do
attr_reader :selenium_driver
alias :page :selenium_driver
before(:all) do
@selenium_driver = Selenium::Client::Driver.new \
:host => "localhost",
:port => 4444,
:browser => "*firefox",
:url => "http://www.google.com",
:timeout_in_second => 60
end
before(:each) do
selenium_driver.start_new_browser_session
end
# The system capture need to happen BEFORE closing the Selenium session
append_after(:each) do
@selenium_driver.close_current_browser_session
end
it "can find Selenium" do
page.open "/"
page.title.should eql("Google")
page.type "q", "Selenium seleniumhq"
page.click "btnG", :wait_for => :page
page.value("q").should eql("Selenium seleniumhq")
page.text?("seleniumhq.org").should be_true
page.title.should eql("Selenium seleniumhq - Google Search")
page.text?("seleniumhq.org").should be_true
page.element?("link=Cached").should be_true
end
end