rubyselenium-webdrivercucumbercapybarapoltergeist

Capybara Upgrade Capybara::Query


I have an old project with Capybara version 2.7.1. One file has the following code

module Capybara
  module Node
    module Finders
      def all(*args)
        using_wait_time 1 do
          xpath = args.find { |a| a.is_a? String }
          has_selector? xpath
          query = Capybara::Query::Query.new(*args)
          synchronize(1) do
            result = query.resolve_for(self)
            raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count?
            result
          end
        end
      end
    end
  end
end

We have now upgraded to Capybara 3.15.0 and looks like Capybara::Query has been deprecated. I have tried using Queries::SelectorQuery instead of Query as shown below

session_options = Capybara.session_options
query = Capybara::Queries::SelectorQuery.new(*args, session_options: session_options)

But following assertions are failing

def content_xpath
  unless @content_xpath
    @content_xpath = "//td[@class='clsCenterButton' and ./label[contains(text(),'#{@label}')]]"
    @content_xpath = "//td[@class='clsCenterButton' and ./label[@title='#{@label}']]" if page.all(@content_xpath, visible: true).count>1
  end
  @content_xpath
end

Unused parameters passed to Capybara::Queries::SelectorQuery : [{:visible=>true}] (ArgumentError)

using_wait_time 10 do
  expect(page).to have_selector content_xpath
  expect(page).to have_selector content_xpath, visible: !(@collapsed)
end

Unused parameters passed to Capybara::Queries::SelectorQuery : [{:visible=>true}] (ArgumentError)

Gemfile (before Upgrade)

source 'http://rubygems.org'
ruby '2.0.0'

gem 'cucumber', '2.0.0'
gem 'gherkin'
gem 'rspec-expectations', '3.2'
gem 'rspec'
gem 'capybara', '2.7.1'
gem 'selenium-webdriver', '2.53.4'
gem 'cuporter', '~>0.3.14'
gem 'nokogiri', '~>1.6.0'
gem 'savon', '~>2.1.0'
gem 'nori', '~>2.0.4'
gem 'chronic', '0.9.1'
gem 'json', '~>1.7.6'
gem 'rest-client', '~>1.6.7'
gem 'flog', '~>4.1.0'
gem 'flay', '~>2.3.0'
gem 'roodi', '~>2.1.0'
gem "require_all", "~> 1.3.2"
gem 'mongo', "~> 1.12.5"
gem 'bson_ext', "~> 1.12.5"
gem 'xml-simple', '~> 1.1.3'
gem 'roo', '~> 1.2.3'
gem "zip-zip", "~> 0.2"
gem 'rubyzip', '1.0.0'
gem 'tiny_tds', '0.7.0'
gem 'poltergeist', '1.10.0'
gem 'addressable', '2.4.0'
gem 'rack', '1.6.4'
gem 'cuke_sniffer'
gem 'rubocop'
gem 'net-ssh', '2.9.2'
gem 'sinatra'
gem 'cucumber_statistics'
gem 'activesupport', '4.2.5.2'
gem 'headless', '2.2.3'
gem 'colorize'
gem 'parallel'
gem 'parallel_tests'

Gemfile (after Upgrade)

source 'http://rubygems.org'
ruby '2.3.0'

gem 'cucumber', '2.2.0'
gem 'gherkin', '6.0.15'
gem 'rspec-expectations', '3.8.2'
gem 'rspec', '3.8.0'
gem 'capybara', '3.15.0'
gem 'selenium-webdriver', '3.141.0'
gem 'cuporter', '0.3.14'
gem 'nokogiri', '1.10.2'
gem 'savon', '2.12.0'
gem 'nori', '2.6.0'
gem 'chronic', '0.10.2'
gem 'json', '2.2.0'
gem 'rest-client', '2.0.2'
gem 'flog', '4.6.2'
gem 'flay', '2.12.0'
gem 'roodi', '5.0.0'
gem 'require_all', '1.5.0'
gem 'mongo', '2.8.0'
gem 'bson_ext', '1.5.1'
gem 'xml-simple', '1.1.5'
gem 'roo', '2.8.2'
gem "zip-zip", '0.3'
gem 'rubyzip', '1.2.2'
gem 'tiny_tds', '2.1.2'
gem 'poltergeist', '1.18.1'
gem 'addressable', '2.6.0'
gem 'rack', '2.0.6'
gem 'cuke_sniffer', '1.1.0'
gem 'rubocop', '0.66.0'
gem 'net-ssh', '5.2.0'
gem 'sinatra', '2.0.5'
gem 'cucumber_statistics', '2.3.0'
gem 'activesupport', '5.2.2.1'
gem 'headless', '2.3.1'
gem 'colorize', '0.8.1'
gem 'parallel', '1.16.0'
gem 'parallel_tests', '2.28.0'
gem 'geckodriver-helper', '0.23.0'

Any suggestions?


Solution

  • It looks like your all method was just trying to add waiting behavior to the Capybara built-in all method (and doing it in a very strange way that would break the flexibility of selector types too). That became the default behavior in Capybara 3 anyway, so I'd recommend just removing your all monkeypatch.