我在项目上将Selenium与rspec结合使用,并从Selenium IDE的自定义格式化程序生成代码。
硒有很多,但是我使用Selenium-
RC成功http://seleniumhq.org/download/,所以请下载到您的PC。
这是我的步骤:
- 解压缩并运行> java -jar selenium-server.jar
- 打开selenium-client-ruby,阅读文档,跟随它,您将获得成功!
- gem install rspec,rspec-rails版本1.2.6(不是,您需要注释selenium-client源代码的版本限制)
- gem install硒客户端
- 打开Selenium-IDE(当然是Firefox),打开选项->选项->格式
- 单击添加,然后将此代码粘贴到http://www.techdarkside.com/rspec_export.txt中
现在,您只需要为我导出规范到您的规范文件夹,我就使用spec / features / xxxx_spec.rb参见下面的代码。
在这里可以找到非常相似的方法
对于webrat + cucumber,最新的Rspec手册将为您提供所需的一切。(他们还没有硒+黄瓜章节完成)
例
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 endend


