Test that a CSS selector is present with Cucumber

Updated . Posted . Visible to the public.

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

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

Here is the step definition for Capybara:

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:

Then /^I should (not )?see an element "([^"]*)"$/ do |negate, selector|
  expectation = negate ? :should_not : :should
  response.send(expectation, have_tag(selector))
end
Henning Koch
Last edit
Keywords
assert, element, exists
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2010-11-03 10:44)