appium / appium_capybara

Gem enabling appium support in capybara
40 stars 35 forks source link

Issue with capybara >= 3.39.2: #find_by_id crashes with undefined method `find_custom' for #<Capybara::Selenium::Driver:... #73

Closed ndbroadbent closed 1 month ago

ndbroadbent commented 2 months ago

Hi there, I'm seeing this error when I use appium_capybara 1.10.0. I tried updating to 3.0.0 but it looks like some dependency versions get downgraded:

bundle update appium_capybara
Fetching gem metadata from https://rubygems.org/.......
Resolving dependencies...
Using appium_lib_core 5.2.0 (was 9.1.3)
Using appium_lib 12.0.1 (was 15.1.0)
Using appium_capybara 3.0.0 (was 1.10.0)
Bundle updated!

Here's the issue with appium_capybara 1.10.0:

Failures:

  1) Swagger Swagger UI the authentication endpoint can be tested successfully
     Failure/Error: find_by_id('operations-PDF-testAuthentication').click

     NoMethodError:
       undefined method `find_custom' for #<Capybara::Selenium::Driver:0x0000000129a0f378 @app=#<Rack::URLMap:0x000000011f7df800 @known_hosts=#<Set: {}>, @mapping=[[nil, "", /^(.*)/n, #<DocSpring::Application>]]>, @browser=#<Selenium::WebDriver::Chrome::Driver:0x..fd0f9bb48625fb04e browser=:chrome>, @exit_status=nil, @frame_handles={}, @options={:browser=>:chrome, :clear_local_storage=>nil, :clear_session_storage=>nil, :options=>#<Selenium::WebDriver::Chrome::Options:0x0000000129a074c0 @options={:args=>["--auto-open-devtools-for-tabs", "--disable-logging", "--window-size=1280,1000", "--disable-site-isolation-trials", "--disable-features=OptimizationGuideModelDownloading,OptimizationHintsFetching,OptimizationTargetPrediction,OptimizationHints", "--disable-dev-shm-usage", "--safebrowsing-disable-auto-update", "--mute-audio", "--ignore-certificate-errors", "--proxy-server=localhost:64554", "--proxy-bypass-list=127.0.0.1;localhost;minio.localhost;testexternalsite.localhost;docspring.localhost;app.docspring.localhost;api.docspring.localhost;admin.docspring.localhost"], :prefs=>{"devtools"=>{"preferences"=>{"currentDockState"=>"\"bottom\"", "panel-selectedTab"=>"\"console\""}}, "browser"=>{"enable_spellchecking"=>false}}, :emulation=>{}, :local_state=>{}, :exclude_switches=>[], :perf_logging_prefs=>{}, :window_types=>[], :browser_name=>"chrome", "goog:loggingPrefs"=>{:browser=>"ALL", :client=>"ALL", :driver=>"ALL", :server=>"ALL"}, :binary=>"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", :browser_version=>nil}, @profile=nil, @logging_prefs={}, @encoded_extensions=[], @extensions=[]>, :service=>#<Selenium::WebDriver::Chrome::Service:0x0000000129a0f5f8 @executable_path="/usr/local/bin/chromedriver", @host="127.0.0.1", @port=9515, @log=nil, @args=["--log-path=/Users/ndbroadbent/code/docspring/log/chromedriver.log", "--log-level=INFO"]>, :http_client=>#<Capybara::Selenium::PersistentClient:0x0000000129a94fa0 @open_timeout=nil, @read_timeout=nil, @server_url=#<URI::HTTP http://127.0.0.1:9515/>, @common_headers={"Accept"=>"application/json", "Content-Type"=>"application/json; charset=UTF-8", "User-Agent"=>"appium/ruby_lib_core/9.1.3 (selenium/4.22.0 (ruby macosx))"}, @proxy=nil, @http=#<Net::HTTP 127.0.0.1:9515 open=true>>, :native_displayed=>false}, @node_class=Capybara::Selenium::Node, @session=#<Capybara::Session>, @invalid_element_errors=[Selenium::WebDriver::Error::StaleElementReferenceError, Selenium::WebDriver::Error::ElementNotInteractableError, Selenium::WebDriver::Error::InvalidSelectorError, Selenium::WebDriver::Error::ElementClickInterceptedError, Selenium::WebDriver::Error::NoSuchElementError, Selenium::WebDriver::Error::InvalidArgumentError, Selenium::WebDriver::Error::DetachedShadowRootError], @chromedriver_version=125.0>

           base.find_custom(finder, locator)
               ^^^^^^^^^^^^
       Did you mean?  find_css
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/appium_capybara-1.10.0/lib/appium_capybara/ext/base_ext.rb:3:in `find_custom'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/appium_capybara-1.10.0/lib/appium_capybara/ext/selector_query_ext.rb:37:in `find_nodes_by_selector_format'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/appium_capybara-1.10.0/lib/appium_capybara/ext/selector_query_ext.rb:9:in `block in resolve_for'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/capybara-3.39.2/lib/capybara/node/base.rb:77:in `synchronize'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/appium_capybara-1.10.0/lib/appium_capybara/ext/selector_query_ext.rb:8:in `resolve_for'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/capybara-3.39.2/lib/capybara/node/finders.rb:303:in `block in synced_resolve'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/capybara-3.39.2/lib/capybara/node/base.rb:84:in `synchronize'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/capybara-3.39.2/lib/capybara/node/finders.rb:301:in `synced_resolve'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/capybara-3.39.2/lib/capybara/node/finders.rb:60:in `find'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/capybara-3.39.2/lib/capybara/node/finders.rb:199:in `find_by_id'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/capybara-3.39.2/lib/capybara/session.rb:773:in `find_by_id'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/capybara-3.39.2/lib/capybara/dsl.rb:52:in `call'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/capybara-3.39.2/lib/capybara/dsl.rb:52:in `find_by_id'
     # ./spec/features/swagger_spec.rb:47:in `block (3 levels) in <main>'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:262:in `instance_exec'
     # /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:262:in `block in run'

I think the following can be ignored, even though it's the latest version of appium_capybara:


With appium_capybara 3.0.0, I get this crash due to the older version of appium_lib_core (5.2.0 instead of 9.1.3):

❯ rspec -b ./spec/features/swagger_spec.rb:29
/Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/appium_lib_core-5.2.0/lib/appium_lib_core/common/base/driver.rb:32:in `<class:Driver>': uninitialized constant Selenium::WebDriver::DriverExtensions::HasRemoteStatus

        include ::Selenium::WebDriver::DriverExtensions::HasRemoteStatus
                                                       ^^^^^^^^^^^^^^^^^ (NameError)
    from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/appium_lib_core-5.2.0/lib/appium_lib_core/common/base/driver.rb:29:in `<class:Base>'
    from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/appium_lib_core-5.2.0/lib/appium_lib_core/common/base/driver.rb:28:in `<module:Core>'
    from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/appium_lib_core-5.2.0/lib/appium_lib_core/common/base/driver.rb:27:in `<module:Appium>'
    from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/appium_lib_core-5.2.0/lib/appium_lib_core/common/base/driver.rb:26:in `<main>'
    from /Users/ndbroadbent/.local/share/mise/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/appium_lib_core-5.2.0/lib/appium_lib_core/common/base.rb:35:in `require_relative
ndbroadbent commented 2 months ago

It works if I replace find_by_id with find. (Just have to disable our Capybara/SpecificFinders RuboCop rule, which prefers find_by_id.)

KazuCocoa commented 2 months ago

I have dropped the ~> limitation as 3.1.0 first. The version will let users install higher appium_lib_core and appium_lib.

KazuCocoa commented 2 months ago

I guess... in the case, https://github.com/appium/appium_capybara/blob/master/lib/appium_capybara/ext/selector_query_ext.rb#L37 was called. It should be raise an exception based on the original capybara code. https://github.com/teamcapybara/capybara/blob/a7ebe1216f8d65f2e96c170437a732777353a81d/lib/capybara/queries/selector_query.rb#L247

or some method overrode. Please try out with latest one first. I did some modifications between them before.

I also wondered if https://github.com/appium/appium_capybara/blob/master/example/spec/capybara_init.rb#L18 would affect unexpected method overrode (which is "true" by default, it means the appiun's driver will be used with $ https://github.com/appium/ruby_lib/blob/4a74c60937e66bf028a66e4f05a324ce8b2077ce/lib/appium_lib/driver.rb#L200

ndbroadbent commented 1 month ago

Thank you for dropping the ~> limitation, that helped a lot! I'm getting much further now, but will open a new issue for a different crash I'm seeing.

KazuCocoa commented 1 month ago

Sure, closing this ticket