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 |
there was a long-standing ticket on capybara's issue tracker for it and various people trying to fix it, I don't know if it's still there or not, I haven't tried to use that feature for a long time.
Thanks much. Currently using one of the workarounds from that github issue
but was hoping you had solved it.
…On Wed, Mar 16, 2011 at 11:04 PM, nruth < ***@***.***>wrote:
there was a long-standing ticket on capybara's issue tracker for it and
various people trying to fix it, I don't know if it's still there or not, I
haven't tried to use that feature for a long time.
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/411453
Got a link to the issue?
It's been awhile but I think it was this one teamcapybara/capybara#81
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have you found a solution for this?