首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >黄瓜+ Webrat + Selenium指南

黄瓜+ Webrat + Selenium指南
EN

Stack Overflow用户
提问于 2009-09-04 10:05:33
回答 1查看 5.8K关注 0票数 12

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-09-04 17:42:14

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

有很多用于rails的selenium,但是我成功地使用了Selenium-RC http://seleniumhq.org/download/,所以请下载到您的pc上。

以下是我的步骤:

selenium-server.jar

  • Open selenium-client -
  1. 解压和run> -jar selenium-client-ruby,阅读文档,按照文档操作,您将获得成功!
  2. gem安装rspec,rspec-rails版本1.2.6 (如果不是,您需要注释Selenium-client源代码的版本限制)
  3. gem安装selenium-client
  4. Open Selenium-IDE (当然是Firefox),打开Options -> Options -> rspec Add,然后将此代码粘贴到http://www.techdarkside.com/rspec_export.txt

现在,您只需为我将spec导出到您的spec文件夹,我使用spec/feature/xxxx_spec.rb查看下面的代码。

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

对于webrat+cucumber,最新的Rspec book将为您提供所需的一切。(他们还没有硒+黄瓜章节整理)

示例

代码语言:javascript
复制
 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
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1378333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档