Fix random Capybara::Webkit::InvalidResponseError failure #595

Closed
wants to merge 4 commits into
from

Projects

None yet

3 participants

Contributor
eagletmt commented Dec 3, 2013

This pull-request fixes the random Capybara::Webkit::InvalidResponseError failure described in #550.

The problem is a kind of "time of check to time of use" issue. The current webkit checks the validity of node index before actual Node command.
https://github.com/thoughtbot/capybara-webkit/blob/f35e2df0df3b2e253d78ab96afa670662f862037/lib/capybara/webkit/node.rb#L128-L134
But it could be broken in the following scenario:

  1. Check the validity of index by sending Node isAttached.
  2. The index becomes invalid by DOM mutation or asynchronous redirection, etc..
  3. Send actual Node command to the index which is no longer valid.

My pull-request makes the validity check atomic. By checking each time in JavaScript and throw NodeNotAttachedError from JavaScript, "time of check to time of use" issue should be fixed.

Collaborator
mhoran commented Dec 3, 2013

This looks great! One problem with NodeNotAttached is that it's not super informative to the user. Perhaps we could provide a more informative message to the user, e.g. "element at [index] no longer present in the DOM". Even better, providing an xpath to that element (though that may not be possible).

Thoughts, @jferris?

Contributor
eagletmt commented Dec 5, 2013

I tweaked error message as suggested by @mhoran .

I found another fix of my pull-request.
dragTo and equals command take a node index as an argument, but it isn't checked.
If an argument node index is invalid, NodeNotAttachedError should be raised.

Owner
jferris commented Dec 6, 2013

Awesome work! Thanks for submitting.

I've rebased, squashed, and merged this as 6945ed5 on master. It will go out with the next release.

@jferris jferris closed this Dec 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment