【发布时间】: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
我在 Rails 2.3.9 项目中使用 capybara 和 cucumber。
我有用户索引页面,那里有两条记录。使用 capybara 如何断言页面中只有两条记录。
HTML结构是这样的
<div class='records'>
<li>record 1<li>
<li>record 2 </li>
</div>
【问题讨论】:
标签: html ruby cucumber capybara
这应该可以为您的 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 => 2) 也可以