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

Check Ferrum::NodeNotFoundError to force Capybara reruns #125

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rogercampos
Copy link

I realized cuprite is not respecting the wait time on find, same as described here:

#122

Cuprite defines the following exceptions to be caught by capybara and allow retries:

    def invalid_element_errors
      [Capybara::Cuprite::ObsoleteNode,
       Capybara::Cuprite::MouseEventFailed,
       Ferrum::NoExecutionContextError]
    end

But some find methods go via Driver#find -> Browser#find, not via Node#find, so Ferrum::NodeNotFoundError is not rescued and re-raised as Capybara::Cuprite::ObsoleteNode.

I added in this PR a rescue and re-raise also on Browser#find, but other solutions are also possible.

@route
Copy link
Member

route commented Jul 9, 2020

@rogercampos thank you! Hm could we come up with the test somehow? Don't quite understand the issue or the consequences of this addition..

@rogercampos
Copy link
Author

A test to assert Capybara::Cuprite::ObsoleteNode is raised when using Driver#find? oks!

Don't quite understand the issue or the consequences of this addition..

Capybara is responsible to manage the retry mechanism when finding nodes or interacting with the page in general. This always happens, when clicking a button but the page is still not loaded, or when the page changes because of JS dom manipulation for example.

The underlying driver must communicate this to capybara by using exceptions. Either the Capybara::ElementNotFound exception, or defining custom exceptions to be considered as "this needs a retry". This is accomplished via Driver#invalid_element_errors.

https://github.com/teamcapybara/capybara/blob/3.33_stable/lib/capybara/node/base.rb#L56

Cuprite implemented this at the node level, but not in the driver, and Capybara is calling this from /node/base.rb:118:in find_xpath'"`.

I don't know how drivers are supposed to interact with capybara, maybe the fix is someplace else.

This is a backtrace example, where you can see the trace between capybara, cuprite and ferrum

"Could not find node with given id"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/browser/client.rb:84:in `raise_browser_error'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/browser/client.rb:49:in `command'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/page.rb:137:in `command'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/frame/runtime.rb:182:in `handle_response'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/frame/runtime.rb:187:in `block in handle_response'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/frame/runtime.rb:223:in `block in reduce_props'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/frame/runtime.rb:221:in `each'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/frame/runtime.rb:221:in `reduce'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/frame/runtime.rb:221:in `reduce_props'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/frame/runtime.rb:185:in `handle_response'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/frame/runtime.rb:147:in `block in call'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum.rb:117:in `with_attempts'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/frame/runtime.rb:131:in `call'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/ferrum-0.8/lib/ferrum/frame/runtime.rb:64:in `evaluate'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/2.6.0/forwardable.rb:230:in `evaluate'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/2.6.0/forwardable.rb:230:in `evaluate'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/cuprite-0.10/lib/capybara/cuprite/browser.rb:181:in `find_all'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/cuprite-0.10/lib/capybara/cuprite/browser.rb:58:in `find'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/cuprite-0.10/lib/capybara/cuprite/driver.rb:88:in `find'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/cuprite-0.10/lib/capybara/cuprite/driver.rb:80:in `find_xpath'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.33.0/lib/capybara/node/base.rb:118:in `find_xpath'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.33.0/lib/capybara/queries/selector_query.rb:250:in `find_nodes_by_selector_format'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.33.0/lib/capybara/queries/selector_query.rb:160:in `block in resolve_for'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.33.0/lib/capybara/node/base.rb:77:in `synchronize'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.33.0/lib/capybara/queries/selector_query.rb:159:in `resolve_for'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.33.0/lib/capybara/node/finders.rb:293:in `block in synced_resolve'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.33.0/lib/capybara/node/base.rb:83:in `synchronize'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.33.0/lib/capybara/node/finders.rb:291:in `synced_resolve'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.33.0/lib/capybara/node/finders.rb:52:in `find'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.33.0/lib/capybara/node/actions.rb:26:in `click_link_or_button'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.33.0/lib/capybara/session.rb:759:in `block (2 levels) in <class:Session>'"
"/Users/elnner/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.33.0/lib/capybara/dsl.rb:58:in `block (2 levels) in <module:DSL>'"
"/Users/elnner/code/camaloon/spec/support/pages/customization/product_show_page.rb:32:in `block in <class:ShowPage>'"

@grzuy
Copy link

grzuy commented Sep 4, 2020

Also hitting this issue.

Thanks @rogercampos for the fix attempt!

but other solutions are also possible.

Would the following alternative implementation also work?

diff --git a/lib/capybara/cuprite/driver.rb b/lib/capybara/cuprite/driver.rb
index 75782be..a8e94cf 100644
--- a/lib/capybara/cuprite/driver.rb
+++ b/lib/capybara/cuprite/driver.rb
@@ -359,7 +359,8 @@ module Capybara::Cuprite
     def invalid_element_errors
       [Capybara::Cuprite::ObsoleteNode,
        Capybara::Cuprite::MouseEventFailed,
-       Ferrum::NoExecutionContextError]
+       Ferrum::NoExecutionContextError,
+       Ferrum::NodeNotFoundError]
     end
 
     def go_back

With the benefit that if wait times out you get the original exception instead of maybe confusing ObsoleteNode error?

nherzing added a commit to parachutehealth/cuprite that referenced this pull request Oct 19, 2020
@georf
Copy link

georf commented Jan 14, 2021

I got the same problem. I tried it with the fork https://github.com/parachutehealth/cuprite and think, this is the better choice.

@georf
Copy link

georf commented Feb 24, 2021

Thanks for merging! I think this one can closed without merging.

saikumar-everest pushed a commit to saikumar-everest/cuprite that referenced this pull request Jun 30, 2021
@Mifrill
Copy link
Collaborator

Mifrill commented Sep 8, 2021

Hi, @rogercampos can you please check out this PR: #125?
Is it solves your case and we can close this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants