Created
May 24, 2010 02:10
-
-
Save nruth/411453 to your computer and use it in GitHub Desktop.
capybara hidden element has_content example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ignore-hidden-elements | |
Feature: Div help content hiding and revealing | |
In order to keep help text available but neatly tucked away when not needed | |
As a designer | |
I want javascript to detect div.help and hide it and its contents, replacing with a link to reveal it again | |
Background: | |
#this is a rails app with a Page model and a path_to entry for visiting them in features like this (using Pickle for cucumber / machinist integration) | |
Given a page exists with content: "<div class='help'>foobar</div>" | |
@rack-test | |
Scenario: no javascript, help is always visible | |
When I go to the page | |
Then I should see "foobar" within "div.help" | |
@javascript | |
Scenario: javascript should hide it | |
When I go to the page | |
#the next test passes | |
Then the page should not match css selector "div.help" | |
#but this one fails, it matches the content despite it being hidden & Capybara being told to ignore hidden elements | |
Then I should not see "foobar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Then /^the page should match css selector "([^\"]*)"$/ do |selector| | |
page.should have_css(selector) | |
end | |
Then /^the page should not match css selector "([^\"]*)"$/ do |selector| | |
page.should have_no_css(selector) | |
end | |
#and from cucumber rails: | |
Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector| | |
regexp = Regexp.new(regexp) | |
with_scope(selector) do | |
if defined?(Spec::Rails::Matchers) | |
page.should have_xpath('//*', :text => regexp) | |
else | |
assert page.has_xpath?('//*', :text => regexp) | |
end | |
end | |
end | |
Then /^(?:|I )should not see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector| | |
with_scope(selector) do | |
if defined?(Spec::Rails::Matchers) | |
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
Got a link to the issue?