0

我是使用 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">

如果它没有通过这个测试,知道如何设置一个复选框来检查它也会很有帮助。

非常感谢任何提供帮助的人。

4

2 回答 2

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

于 2013-02-10T16:40:32.823 回答
0

如果选中复选框,则它将与 css 关联。那就是复选框被选中,而不是它上面会“选中”css。

于 2013-01-22T13:06:45.133 回答