-
-
Notifications
You must be signed in to change notification settings - Fork 97
Check Ferrum::NodeNotFoundError to force Capybara reruns#125
Check Ferrum::NodeNotFoundError to force Capybara reruns #125rogercampos wants to merge 1 commit intorubycdp:main from
Conversation
@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
commented
Jul 9, 2020
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>'"
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?
09d2b9f to
f17317d
Compare
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
commented
Feb 24, 2021
Thanks for merging! I think this one can closed without merging.
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?
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:
But some find methods go via
Driver#find->Browser#find, not viaNode#find, soFerrum::NodeNotFoundErroris not rescued and re-raised asCapybara::Cuprite::ObsoleteNode.I added in this PR a rescue and re-raise also on
Browser#find, but other solutions are also possible.