Posted almost 10 years ago. Visible to the public.

Test that a CSS selector is present with Cucumber

This note describes a Cucumber step definition that lets you test whether or not a CSS selector is present on the site:

Copy
Then I should see an element "#sign_in" But I should not see an element "#sign_out"

Here is the step definition for Capybara:

Copy
Then /^I should (not )?see an element "([^"]*)"$/ do |negate, selector| expectation = negate ? :should_not : :should page.send(expectation, have_css(selector)) end

Here is the step definition for Webrat:

Copy
Then /^I should (not )?see an element "([^"]*)"$/ do |negate, selector| expectation = negate ? :should_not : :should response.send(expectation, have_tag(selector)) end

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Avatar
Henning Koch
Last edit:
about 9 years ago
Keywords:
assert, element, exists
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more