Capybara: Test that a string is visible as static text

Posted . Visible to the public.

This is surprisingly difficult when there is a <textarea> with the same text on the page, but you really want to see the letters as static text in a <p> or similiar.

The step definition below lets you say:

Then I should see the text "foo"

You should not look too closely at the step definition because when you see the light, it will blind you.

Then /^I should see the text "(.*?)"$/ do |text|
  elements = page.all('*', :text => text).reject { |element| element.tag_name == 'textarea' || element.all('*', :text => text).present? }
  elements.should be_present
end
Henning Koch
Last edit
Keywords
rendered, appear
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2012-03-15 16:51)