【问题标题】:Cucumber + Webrat + Selenium guideCucumber + Webrat + Selenium 指南
【发布时间】:2010-11-25 14:05:06
【问题描述】:

我使用 Cucumber 和 Webrat 已经有一段时间了。我现在需要开始编写涉及 AJAX 交互的行为,所以我想为 Webrat 使用 Selenium 适配器。 谁能指出一个简单且更新的分步指南,用于安装和配置 selenium+webrat+cucumber? 我希望能够将 javascript 场景与非 javascript 场景混合使用。

【问题讨论】:

    标签: ruby-on-rails ruby selenium cucumber webrat


    【解决方案1】:

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

    rails 有很多 selenium,但我使用 Selenium-RC http://seleniumhq.org/download/ 成功,所以下载到你的电脑上。

    这是我的步骤:

    1. 解压并运行> java -jar selenium-server.jar
    2. 打开selenium-client-ruby,阅读文档,跟着做就成功了!
    3. gem install rspec, rspec-rails version 1.2.6(不是,需要注释selenium-client源代码的版本限制)
    4. gem 安装 selenium-client
    5. 打开 Selenium-IDE(当然是 Firefox),打开选项 -> 选项 -> 格式
    6. 单击添加,并将此代码粘贴到http://www.techdarkside.com/rspec_export.txt

    现在,您只需为我将规范导出到您的规范文件夹,我使用 spec/features/xxxx_spec.rb 参见下面的代码。

    非常相似的方法可以在here找到

    对于 webrat+cucumber,最新的Rspec book 将满足您的所有需求。 (他们还没有 selenium + cucumber 章节完成)

    例子

     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
    

    【讨论】:

      猜你喜欢
      • 2010-12-31
      • 1970-01-01
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      • 2010-12-08
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      相关资源
      最近更新 更多