Skip to content

Instantly share code, notes, and snippets.

@gabehollombe
Created May 14, 2010 05:13
Show Gist options
  • Save gabehollombe/400838 to your computer and use it in GitHub Desktop.
Save gabehollombe/400838 to your computer and use it in GitHub Desktop.
Testing text visibility on page with capybara
#relevant lines in features/support/env.rb
Capybara.default_selector = :css
Capybara.javascript_driver = :culerity
Capybara.ignore_hidden_elements = true
#features/hidden_text_testing.feature
@javascript
Scenario: Testing test hidden via inline style with 'should not see'
When I visit the the public index.html page
Then I should not see "Hidden Via Comment"
And I should not see "Hidden Via Inline Style"
And I should not see "Hidden Via Class"
#public/index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test App</title>
<style type='text/css'>
.hidden {
display: none;
}
</style>
</head>
<body>
Visible
<span class='hidden'>Hidden Via Class</span>
<span style='display: none;'>Hidden Via Inline Style</span>
<!-- Hidden Via Comment -->
</body>
</html>
#features/step_definitions/custom_web_steps.rb
When /^I visit the the public index\.html page$/ do
visit '/'
end
#features/step_definitions/web_steps.rb
#contains the default generated capybara web steps.
#Including:
Then /^(?:|I )should not see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
with_scope(selector) do
if page.respond_to? :should
page.should have_no_content(text)
else
assert page.has_no_content?(text)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment