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 `within`block #2157

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

Comments

Projects
None yet
2 participants
@spaghetticode
Copy link

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

commented Feb 15, 2019

@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

This comment has been minimized.

Copy link
Author

commented Feb 16, 2019

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

@twalpole

This comment has been minimized.

Copy link
Member

commented Feb 18, 2019

Closed via PR #2159

@twalpole twalpole closed this Feb 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.