【问题标题】:How to verify number of records using capybara如何使用 capybara 验证记录数
【发布时间】:2010-09-12 02:31:05
【问题描述】:

我在 Rails 2.3.9 项目中使用 capybara 和 cucumber。

我有用户索引页面,那里有两条记录。使用 capybara 如何断言页面中只有两条记录。

HTML结构是这样的

<div class='records'>
  <li>record 1<li>
  <li>record 2 </li>
</div>

【问题讨论】:

    标签: html ruby cucumber capybara


    【解决方案1】:

    这应该可以为您的 Cucumber 步骤定义解决问题:

    page.has_css?("div.records li", :count => 2)
    

    还有page.has_xpath?(不过我不懂xpath)

    如果你使用的是 Rspec,你可以用 Rspec 的方式来表达它:

    page.should have_css("div.records li", :count => 2)
    

    昨天我不得不解决一个非常相似的问题;这是我最终得到的完整步骤定义。

    Then /^I should see only (\d+) tasks$/ do |number_of_tasks|
      page.should have_css("table tr.task", :count => number_of_tasks.to_i)
    end
    

    【讨论】:

    • page.should have_select("table tr", :count =&gt; 2) 也可以
    猜你喜欢
    • 2015-03-23
    • 2016-08-13
    • 2020-10-05
    • 1970-01-01
    • 2017-01-10
    • 2010-11-26
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多