黄瓜 +韦伯拉特硒指南

发布于 2024-08-03 09:35:53 字数 184 浏览 1 评论 0原文

我使用 Cucumber 和 Webrat 一段时间了。我现在需要开始编写涉及 AJAX 交互的行为,因此我考虑使用 Webrat 的 Selenium 适配器。 任何人都可以指出安装和配置 selenium+webrat+cucumber 的简单且更新的分步指南吗? 我希望能够将 javascript 场景与非 javascript 场景混合在一起。

I have been using Cucumber and Webrat for a while. I now need to start writing behaviour that involve AJAX interactions so I was thinking to use the Selenium adapter for Webrat.
Can anyone point out a easy and updated step-by-step guide for installing and configuring selenium+webrat+cucumber?
I would like to be able to mix javascript scenario with non-javascript scenarios.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软甜啾 2024-08-10 09:35:53

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

Rails 有很多硒,但我成功使用 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/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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文