`has_content?` is not matching when it should #175

Closed
jfelchner opened this Issue Sep 26, 2011 · 20 comments
@jfelchner

I currently am getting this error when using has_content?. I'm not sure if this is a capybara-webkit issue or if it's a capybara issue. I'm posting it here just in case it's the way that the content is being sent to capybara.

Here is my error output:

expected there to be content "Log in to use your Facebook account with Facebook App Capybara." in
"\nSign UpFacebook helps you connect and share with the people in your life.\nFacebook Login\n
Log in to use your Facebook account with Facebook App Capybara.\nEmail:\nPassword:\n\nKeep me logged in\n
or Sign up for Facebook\nForgot your password?\nEnglish (US)EspañolPortuguês (Brasil)
Français (France)DeutschItalianoالعربيةहिन्दी中文(简体)日本語…\nFacebook © 2011\nMobile · Find Friends ·
Badges · People · Pages · About · Advertising · Create a Page · Developers · Careers · Privacy · 
Terms · Help"

In RSpec, I'm doing this:

page.should have_content 'Log in to use your Facebook account with Facebook App Capybara.'

Does anyone have any idea why this isn't matching?

@halogenandtoast

Have you tried this on master? There is probably a fix for this I pushed. I'll be releasing a new gem shortly

@jfelchner

I have not. Let me give it a try and get back to you. Thanks!

@jfelchner

Ok, I pulled latest and the difference that I notice is that the "\n"'s are now gone from the "actual" output. But the test still fails.

New output:

expected there to be content "Log in to use your Facebook account with Facebook App
Capybara." in "Sign UpFacebook helps you connect and share with the people in your life. Facebook
Login Log in to use your Facebook account with Facebook App Capybara. Email: Password:
Keep me logged in or Sign up for Facebook Forgot your password? English (US)EspañolPortuguês
(Brasil)Français (France)DeutschItalianoالعربيةहिन्दी中文(简体)日本語… Facebook © 2011 Mobile · Find
Friends · Badges · Peo  ple · Pages · About · Advertising · Create a Page · Developers · Careers
 · Privacy · Terms · Help"

It may or may not be related but I'm also noticing that "People" is presented as "Peo ple" which would definitely cause issues if you were trying to search for it. Although I'm assuming this is simply a transformed string and not the actual string used to match against.

@jfelchner

Also I forgot to mention that the exact same code passes fine when I use Selenium.

Finally, one thing which may be causing the discrepancy that I didn't notice before is that in the HTML, "Facebook App Capybara" is a link. Due to the "actual" output, I hadn't considered this to be a possibility. SO, here's what I did:

I tried using:

page.should have_content 'Log in to use your Facebook account with'

Which still failed.

I then tried:

page.should have_link 'Facebook App Capybara'

This passed.

I'm at a loss.

@halogenandtoast

Can you provide the html it's trying to match against to see if we can recreate it?

@jfelchner

Hey @halogenandtoast, sorry for the delay. The HTML page is just the standard Facebook Application login page. I've created a gist with the code to speed up resolution: https://gist.github.com/1259806

I've also created another gist that has the capybara-webkit debug log as well so you can see exactly what it's doing on my system. https://gist.github.com/1259838

Let me know if there is anything else I can do to help you out determining what the problem is.

(I'm using QT 4.7.4 compiled from source using Homebrew)

Thanks!

@krisleech

I'm also having this issue, using open_and_save_page I can clearly see the content exists, but the test fails.

If I use the rack driver all my tests pass.

Unfortunately I'm using Rails 2.3 (without bundler) so I can't try use a gem directly from Git.

If I use :webkit_debug I can also see the content in the HTML dump of the page. I'm not sure how to interpret the debug output but there are lots of << ok's.

@krisleech

I upgraded my Rails 2.3 to use bundler and the git head still seems to have this problem.

@botandrose

I'm also seeing this behavior with evergreen on Rails 2.3 on 1.8.7. but only when using Xvfb on my CI box. Passes when running locally. My only guess is that it might have something to do with encoding? Perhaps the strings don't match because the encodings are different? Totally confused. @jfelchner and @krisleech: are you guys also using Xvfb?

Hilarious error messages:

  Failed: gallery purchase pane by default selects the default size.
    Expected '19 x 24' to equal '19 x 24'.
    in :

  Failed: gallery purchase pane by default displays the print price for the default size.
    Expected '525' to equal '525'.
    in :

etc.

@nielsen

Capybara's FF Selenium driver passes two tests which fail using capybara-webkit; initial partials which are loaded by Sammy.js pass, but an AJAX request which sets the content of a hidden div to the return value of the request, and then show it.

Failures:

1) Information Capture should submit a filled out form
Failure/Error: find('#success').should have_content('Thank you')
expected #has_content?("Thank you") to return true, got false
# ./spec/app_spec.rb:65:in `block (2 levels) in '

2) Information Capture should accept a form for interns
Failure/Error: find('#success').should have_content('Thank you')
expected #has_content?("Thank you") to return true, got false
# ./spec/app_spec.rb:76:in `block (2 levels) in '

Finished in 19.57 seconds
8 examples, 2 failures

Failed examples:

rspec ./spec/app_spec.rb:58 # Information Capture should submit a filled out form
rspec ./spec/app_spec.rb:68 # Information Capture should accept a form for interns
rake aborted!

@krisleech

"@krisleech: are you guys also using Xvfb?"

Sorry, I do not know. I would guess not unless its a default configuration on MacOS.

Encoding could certainly be an issue here.

@sfsekaran

I'm seeing this as well using capybara-webkit.

@JamesCropcho

Also still a problem for me- things pass on OSX, but not on my local Ubuntu machine. Changing the expectation to expect the newline fixes it. (but clearly not a workable solution, since it would then break on OSX)

@avances123

Same bug in

capybara (2.0.2)
capybara-webkit (0.14.2)
@mhoran

@avances123, could you extract a failing test case to help debug this issue? Also, would you please tell us a bit more about your environment? Are you running on Linux or Mac OS X? Are you utilizing any web fonts (Font Awesome, etc.)?

@jaredbeck


Same issue with capybara 2.1.0 and capybara-webkit master branch. Replacing assert page.has_content? with assert page.html.include? makes the test pass again, but is an unsavory workaround.

EDIT: Nevermind, turned out to be a case-sensitivity issue re: text-transform: uppercase 😭 😤

@voondo

@jaredbeck thanks, I had the same issue !! Too bad that capybara cannot handle case-insensitive searches...

@calleerlandsson

Were the other failures also related to text-transform: uppercase CSS rules? If so, are you still experiencing these issues in the current version of capybara-webkit?

@calleerlandsson

I'll close this issue due to inactivity. Please re-open it if you're still experiencing these issues.

@nijotz

Here's something that I just experienced that may help others:

I had a has_content? test that was passing and then started failing. I had changed some versions of some testing libraries and thought it may have been that. Turns out some CSS rules changed so that the content was technically on the page, but wasn't accessible because you couldn't scroll down far enough to see that content. Window size and scrolling may affect this test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment