-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
has_content matches hidden elements w/ Capybara.ignore_hidden_elements #81
Comments
ignore_hidden_elements doesn't seem to change anything for my tests using @Selenium. While I do see the element disappear in the browser as the test runs the test fails on "And I should not see "Billing Address". Changing this to "And I should see "Billing Address" passes. I've yet to find a solution. |
Same here, ignore_hidden_elements setting doesn't make any change in this situation. Looking for a solution EDIT: I've investigated a bit - it filters visible/not visible elements actually GOOD, BUT that selector of content returns bunch of nodes that don't contain the text that we're matching. It returns that node too but filters out as invisible, other shouldnt-be-there nodes are left out so are not counted correctly |
Yeah ignoring hidden elements is a big reason why I wanted to use integration testing and Capybara. Hopefully it gets fixed soon. |
Today I came across https://github.com/alexdunae/premailer/blob/master/lib/premailer/html_to_plain_text.rb . premailer internally uses https://github.com/alexdunae/css_parser to bring all the css properties inline. Right now the issue with "display:none" through css is that capybara only looks for "display:none" as inline style. With premailer/css_parse all the css properties are brought to inline and then check for "display:none" will render right result. Just a thought that popped up in my head when I saw premailer. What say. |
If any one is interested, this is my quick fix.
|
But have to use selector which is not "human-friendly"... so cucumber steps one step further from its one of purposes :-) |
My quick fix doesn't need a selector. If thats what you are commenting on. |
@bjornblomqvist your quick fix works perfectly. Thanks for that :) |
The workaround has a couple of issues. It doesn't correctly handle cases where two elements have the same text but only one is visible. Also, I ran into cases where jQuery was mis-reporting elements as being ':visible' in the same way as celerity. This is the workaround that I ended up with. I realize it's hideous.
In English: filter locator and all of the elements under locator, looking for elements containing the search string. We only care about the lowest nodes, so remove any parent nodes from the search. Filter that list down to the list of visible nodes containing the search text. Finally, to work around the Celerity bug, filter out "visible" nodes which have an ancestor which is hidden. edit Performance was too slow on huge pages when the caller doesn't provide a locator. Updated the code so its performance is better. |
I don't think there is any really good way of handling this right now. This issue doesn't really help us, unless someone can provide any working fix. If you really want this, please reopen with a pull request. |
It looks like we need to be passing Capybara.ignore_hidden_elements along to XPath::HTML. I can hack around this with something like:
but that's not pretty at all. |
Check Capybara's master, we've improved on this a lot, and it's now a lot less inconsistent. |
Hidden elements are properly ignored by have_content in @jnicklas perhaps a new release is in order? This is a blocker for me using Capybara for JS testing, and while I can just use the :git option in Gemfile, the Capybara repo is 6.2MB and Bundler doesn't do --depth so I hesitate to foist it on my teammates. |
+1 for a release. I wasted hours trying to understand why |
I was not successful in upgrading to current master. I had to also upgrade I focused on a ultra basic integration spec with 5 scenarios. All five begin by calling the same After reverting to the last official version (1.1.2 and 0.12.1), I never get a failure. So my dream at this point is an official release of capybara that provides exactly one thing: BTW, the doc in master still states there is a difference between Thanks |
Could you please reopen this issue, or else should I follow another issue? Thanks. |
I too would be interested in a solution to this issue. |
@chazu For now, you can copy paste the |
The code for has_{no_}text methods include the following comment: Unlike has_content this only matches displayable text and specificallyexcludes text contained within non-display nodes such as script or head tags.And then has_{no_}content is aliased to has_{no_}text. Was that an oversight? |
Yes, that's an oversight. |
Since discovering how easy @javascript makes it to test js I've started doing some PE of an existing app with prototype/scriptaculous/lowpro, but have come upon some issues with hidden elements.
Following up from this group posting and my own troubles with this feature/scenarios/stepdefs on selenium, I have produced a feature branch w/ 2 failing specs tested in the rack-test and selenium session specs (I don't have the other bits and bobs installed, sorry).
I'm going to have a poke about the capybara code, but not sure whether I'll get very far with it.
I wonder if it's just a setting not being passed somewhere or other for has_content, since the find matchers seem to be working as expected when turning ignore_hidden_elements on/off.
The text was updated successfully, but these errors were encountered: