Posted almost 10 years ago. Visible to the public.

Using the full power of have_css

Capybara's has_css? matcher has a couple of options you might find useful.

Check that a selector appears a given number of times

Use the :count option like this:

Then /^I should see (\d+) users?$/ do |count| page.should have_css('ul#users li', :count => count.to_i) end

Check that a selector has a given text content

Use the :text option like this:

Then /^I should see a user with name "([^\"]*)"$/ do |name| page.should have_css('ul#users li', :text => name) end

Note that this will only compare substrings, i.e. have_css('div', :text => 'foo') will match "<div>Hello foobear!</div>".
If you require an exact match, you need to find the element and compare its text explicitly.

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Arne Hartherz
Last edit:
almost 4 years ago
by Emanuel De
cucumber, has_css
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Arne Hartherz to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more