thoughtbot / capybara-webkit

A Capybara driver for headless WebKit to test JavaScript web apps
https://thoughtbot.com/open-source
MIT License
1.97k stars 428 forks source link

Option to have Capybara report why an element is deemed invisible #1048

Closed matthewhively closed 6 years ago

matthewhively commented 6 years ago

Hi, I've run into several issues over time where Capybara "falsely" reports that some text on the page is invisible (and therefore expect(page).to have_content mytext fails) I say "falsely" because when a screenshot is taken upon failure the text is clearly visible.

NOTE: I'd rather not change the selector to ignore visibility.

If there is already a way to get extra debugging information then I would appreciate a pointer in that direction. Otherwise, if there could be a flag for an explanation as to why the driver failed in this way that would be very helpful.

Thanks

twalpole commented 6 years ago

Can you provide an example that shows this behavior?

matthewhively commented 6 years ago

Unfortunately I cannot provide a test case at this time since I don't yet understand the invisibility behavior enough to replicate it. I would link you to the test that fails, but it is unfortunately a page within our shopping cart purchase routine.

Either way, whether or not there is a bug in the visibility detection is a different question. I only wish to know if there is already a way to have Capybara report on what aspect of the DOM makes this element invisible (display none, transparency, overlapping element, white on white text.... etc). Then depending on the answer to that, MAYBE there is a bug in the detection routine.

twalpole commented 6 years ago

@matthewhively You have filed this issue on the capybara-webkit project (not Capybara itself). No there is no way to have capybara-webkit report on what aspect of the DOM makes it consider it non-visible.

Assuming you are using the capybara-webkit driver then visibility is determined at https://github.com/thoughtbot/capybara-webkit/blob/master/src/capybara.js#L251 . So if the computed style of an element (or an ancestor) has display 'none' or visibility 'hidden' it is considered non visible. Looking at that, there is a bug in it if an ancestor has visibility 'hidden' a descendant of it with visibility 'visible' should actually be considered visible, whereas capybara-webkit would report it as non-visible. Is that the issue your page is running into? If that is not the issue can you at least provide the HTML (and associated CSS) for the page with the issue?

twalpole commented 6 years ago

Could you please try the visibility_issue branch and see if that solves your issue?

matthewhively commented 6 years ago

Sorry about the confusion with the wrong project, however I'm glad it happened to reveal a bug anyways. Our issue actually appears to be some sort of strange page timeout issue, where the old page content was scanned for the query string, but the new content was what was displayed in the browser (for screenshot). We're still not sure how the visibility factors into this, but it seems like something more fundamental was having problems.