domino icon indicating copy to clipboard operation
domino copied to clipboard

API Inconsistency: find! vs find_by!

Open tf opened this issue 9 years ago • 5 comments

Hi,

I just noticed the addition of the find_by! method in #19. From my point of view, this introduces an unfortunate semantic inconsistency with the find! method added earlier in #14.

When using a JS Capybara driver:

  • find! waits for elements to appear
  • find_by! simply raises an exception if the element is not already on the page

As mentioned in #15, I am not sure how the waiting behavior could be added to find_by! in the presence of computed attributes. As a last resort one could consider renaming find! to something like await. Still this would require a breaking API change.

tf avatar Apr 21 '15 17:04 tf

Hm, interesting point. The ! really just means "it will throw an exception" but I totally understand how Capybara wait behavior can be confusing. IMO the main workaround would be something like wrapping it in a timeout and sleeping and checking until Capybara.current_wait_time.

Although generally I like to follow the capybara pattern of:

  1. Check that we are on the page we expect to be
  2. Look for stuff

So that (1) makes sure we have page content and asserts the context of the test. That way I don't get confused about broken tests as often.

But yeah I agree that I'm not sure how to remedy this exactly!

ngauthier avatar Apr 21 '15 18:04 ngauthier

Well yeah, but sometimes you already are on the correct page but still have to wait for stuff to appear (i.e. ajax).

tf avatar Apr 21 '15 18:04 tf

Yup. Would be nice if find_by! was more capybara-like.

ngauthier avatar Apr 21 '15 18:04 ngauthier

This also seems to be the way capybara implements waiting. Still, it somehow feels like re-implementing capybara features in domino.

tf avatar Apr 22 '15 08:04 tf

Capybara used to expose a wait function but too many people used it so they removed it 😄 On Apr 22, 2015 4:26 AM, "Tim Fischbach" [email protected] wrote:

This also seems to be the way capybara implements waiting https://github.com/jnicklas/capybara/blob/ba5ba340e8847105312de16705a80dfb5ee92475/lib/capybara/node/base.rb#L76. Still, it somehow feels like re-implementing capybara features in domino.

— Reply to this email directly or view it on GitHub https://github.com/ngauthier/domino/issues/20#issuecomment-95072680.

ngauthier avatar Apr 22 '15 11:04 ngauthier