Skip to content
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

[RackTest] Page refresh does not update HTML in a withinblock #2157

Closed
spaghetticode opened this issue Feb 15, 2019 · 4 comments
Closed

[RackTest] Page refresh does not update HTML in a withinblock #2157

spaghetticode opened this issue Feb 15, 2019 · 4 comments

Comments

@spaghetticode
Copy link

spaghetticode commented Feb 15, 2019

Meta

Capybara Version:
3.13.2

Driver Information (and browser if relevant):
it's relevant, as the issue happens only with rack_test. With a JS capable driver (I actually tried only Chrome) the issue is not present.

Expected Behavior

Spec should pass

Actual Behavior

Spec fails

Steps to reproduce

While working on this PR I encountered what I think is a rather rare situation where inside awithin block rack_test fails to find a CSS selector that becomes present after clicking an element inside the within HTML .

What happens is that the node is stale and does not include the changes from the page refresh. This is the actual commit that explains and fixes the spec.

I haven't spent much time in investigating if this can be solved in other ways than splitting the within block in the spec, but I was able to fix the issue and keep the single within block by injecting this code in Capybara:

module CapybaraPatch
  def find_css(css, **options)
    super.presence || begin
      reload
      super
    end
  end
end

Capybara::Node::Base.prepend CapybaraPatch

I'm not confident this is a good fix, as it changes the behavior of Capybara::Node::Base, which I think is used by other drivers too, but I hope it can be useful in pointing someone to the right solution.

@twalpole
Copy link
Member

twalpole commented Feb 15, 2019

Thanks for reporting this. As you stated the provided path is not a good fix because it would affect all drivers and there are plenty of valid situations where find_css would return an empty result set that we don't want to be triggering an extra search for. Your patch would also only affect CSS and not XPath behavior. The root cause of this issue is that the context node is not being detected as stale when the document changes, I will need to play around with the code to see what (if anything) we can do about that.

@twalpole
Copy link
Member

@spaghetticode Please try the issue_2157 branch and let me know if that fixes the problem for you - It's not a final solution yet but is probably the general direction I will go for a final solution.

@spaghetticode
Copy link
Author

@twalpole thank you for the fast feedback, I can confirm the branch works fine 👍🎉

@twalpole
Copy link
Member

Closed via PR #2159

@lock lock bot locked and limited conversation to collaborators Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants