How to verify number of records using capybara

This should do the trick for your Cucumber step definition:

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

There’s also page.has_xpath? (but I don’t understand xpath)

If you’re using Rspec you can phrase it the Rspec way with:

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

I had to solve a very similar problem just yesterday; here’s the full step definition I ended up with.

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)