gpt4 book ai didi

ruby-on-rails - Cucumber + Webrat + Selenium 指南

转载 作者:数据小太阳 更新时间:2023-10-29 06:41:51 25 4
gpt4 key购买 nike

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

最佳答案

我在我的项目中使用带有 rspec 的 Selenium,并从 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. 点击Add,将这段代码粘贴到http://www.techdarkside.com/rspec_export.txt

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

关于ruby-on-rails - Cucumber + Webrat + Selenium 指南,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1378333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com