确保用Capybara检查盒子?

时间:2013-01-15 00:55:33

标签: checkbox cucumber capybara webrat

我是使用Cucumber和Capybara的新手。我在网页上设置了测试,并在尝试运行时遇到此错误。

undefined method `locate' for #<Webrat::Session:0x007fdf2ac41c18> (NoMethodError)
  ./Documents/Work:etc./Raster Media/Cucumber/Klinq Testing/1/features/step_definitions/steps.rb:14:in `/^I make sure the (.*) box is checked$/'
  ./Documents/Work:etc./Raster Media/Cucumber/Klinq Testing/1/features/account.feature:16:in `And I make sure the vendor[tos] box is checked'

我正在努力确保在我的网页中检查一个方框。这是我的步骤定义:

When /^I make sure the (.*) box is checked$/ do |box|
locate(:css, 'box').set(true)

我的env.rb文件:

require 'rspec/expectations'
require 'test/unit/assertions'
require 'capybara'
require 'webrat'
World(Test::Unit::Assertions)
Webrat.configure do |config|
config.mode = :mechanize
end
World do
session = Webrat::Session.new
session.extend(Webrat::Methods)
session.extend(Webrat::Matchers)
session
end

这是我的复选框

的源代码
<input type="checkbox" name="vendor[tos]" value="1" id="vendor[tos]" class="one left">

知道如何设置复选框以检查它是否未通过此测试也是有帮助的。

非常感谢任何帮助过的人。

2 个答案:

答案 0 :(得分:1)

使用Capybara,您可以选中以下复选框:

    When /^I make sure the (.*) box is checked$/ do |box|
      check(box)
    end

'box'可以是id,name或label。

以下是检查方法的Capybara文档的链接:http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions#check-instance_method

答案 1 :(得分:0)

如果选中复选框,则它将与css关联。这是复选框被检查,而不是它将“检查”css。

相关问题