Cucumber + Webrat + Selenium guide

筅森魡賤 提交于 2019-11-30 02:41:50
Jirapong

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:

  1. Unzip and run> java -jar selenium-server.jar
  2. Open selenium-client-ruby, read the doc, follow it you will get success!
  3. gem install rspec, rspec-rails version 1.2.6 (it not, you need to comment version restrict of selenium-client source code)
  4. gem install selenium-client
  5. Open Selenium-IDE (Firefox of course), Open Options -> Options -> Formats
  6. Click Add, and paste this code in http://www.techdarkside.com/rspec_export.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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!