黄瓜+ Webrat + Selenium指南

sou*_*ein 12 ruby selenium ruby-on-rails webrat cucumber

我一直在使用Cucumber和Webrat.我现在需要开始编写涉及AJAX交互的行为,所以我想使用Selenium适配器进行Webrat.有人能指出安装和配置selenium + webrat + cucumber的简单和更新的分步指南吗?我希望能够将javascript场景与非JavaScript场景混合使用.

Jir*_*ong 8

我正在我的项目中使用Selenium和rspec,并从Selenium IDE的自定义格式化程序生成代码.

有很多硒用于铁路,但我成功使用Selenium-RC http://seleniumhq.org/download/,所以下载到你的电脑.

这是我的步骤:

  1. 解压缩并运行> java -jar selenium-server.jar
  2. 打开selenium-client-ruby,阅读文档,按照它你将获得成功!
  3. gem install rspec,rspec-rails版本1.2.6(不是,你需要评论selenium-client源代码的版本限制)
  4. gem install selenium-client
  5. 打开Selenium-IDE(当然是Firefox),打开选项 - >选项 - >格式
  6. 单击"添加",然后将此代码粘贴到http://www.techdarkside.com/rspec_export.txt中

现在,您只需将spec导出到spec文件夹,我使用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
  end

end
Run Code Online (Sandbox Code Playgroud)