【问题标题】:Making sure a box is checked with Capybara?确保用 Capybara 选中一个框?
【发布时间】:2013-02-11 00:40:32
【问题描述】:

我刚开始使用 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">

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

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

【问题讨论】:

    标签: checkbox cucumber capybara webrat


    【解决方案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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2016-07-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多