31

我在 Rails 2.3.9 项目中使用水豚和黄瓜。

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

HTML结构是这样的

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

1 回答 1

48

这应该为您的 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
于 2010-10-05T17:06:31.970 回答