teamcapybara / capybara

Acceptance test framework for web applications

Home Page:http://teamcapybara.github.io/capybara/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ArgumentError: wrong number of arguments (given 2, expected 0..1)

kyrofa opened this issue · comments

selenium-webdriver v4.9.1, released just hours ago, breaks Capybara on Ruby 3.

It introduces a feature (in a patch 🙄) to specify the logging level when creating a logger, and makes use of it. That exposes Ruby-2-era argument forwarding in Capybara that doesn't properly handle forwarding both positional and keyword arguments.

Take this simple example:

class Foo
  def initialize(*args, **kwargs)
    puts "ARGS: #{args}, KWARGS: #{kwargs}"
  end
end

class Bar < Foo
  def initialize(*)
    super
  end
end

puts 'Foo:'
Foo.new('positional', keyword: 'argument')

puts 'Bar:'
Bar.new('positional', keyword: 'argument')

This runs fine on ruby 2.5:

$ rvm-exec 2.5.8 ruby example.rb
Foo:
ARGS: ["positional"], KWARGS: {:keyword=>"argument"}
Bar:
ARGS: ["positional"], KWARGS: {:keyword=>"argument"}

Also fine on 2.7:

$ rvm-exec 2.7.5 ruby example.rb
Foo:
ARGS: ["positional"], KWARGS: {:keyword=>"argument"}
Bar:
ARGS: ["positional"], KWARGS: {:keyword=>"argument"}

However, it does NOT work on 3.0:

$ rvm-exec 3.0.4 ruby example.rb
Foo:
ARGS: ["positional"], KWARGS: {:keyword=>"argument"}
Bar:
ARGS: ["positional", {:keyword=>"argument"}], KWARGS: {}

See also

commented

I ran into this error yesterday as well (ruby 3.2.2/rails 7.1.alpha) and added Selenium::WebDriver.logger.output = 'log/selenium.log' to ApplicationSystemTestCase in test/system/application_system_test_case.rb , which seemed to suppress the error and generates the denoted log file in the log directory.

i'm a novice in this domain so i'll defer to others here for the best solution, but perhaps it's better to have such log files, and to add generalized instructions to the documentation if folks run into this error?

I can confirm that setting Selenium::WebDriver.logger.output does seem to be a workaround for me.

Selenium::WebDriver.logger.output = false also works.

Surely the underlying bug should be fixed rather than documenting the workaround though.

Thanks @kyrofa for the great diagnosis.

As a temporary workaround, I'm interested in what Selenium::WebDriver.logger.output line would correspond to default...

OK, actually as a (temporary!) workaround, it seems to work to simply reference:

Selenium::WebDriver.logger in code before a call to capybara visit.

No need to configure it or assign anything to it, just putting Selenium::WebDriver.logger in your initialization code somewhere seems to work as a workaround.

I guess it lazily initializes the logger through a different code path than the one that was triggering the capybara bug? I can't explain the details. I am unsure if it might change logger semantics in any/all contexts to force logger initialization early like this.

Thanks @clairity for the hint that doing something with Selenium::WebDriver.logger could comprise a workaround.

I still eagerly await a capybara release that fixes the underlying problem!

The real problem here is a breaking change in a patch release of selenium -- not sure how that got approved... will need to check on that

@twalpole if i understand @kyrofa's diagnosis, the change in selenium behavior triggers an already-existing capybara bug (method delegation in a way that stops working the same in ruby 3, and starts failing for methods with keyword args), that just hadn't been triggered (at least in default paths) before.

Whether or not without that bug the selenium change would be considered a breaking change... I guess is for others to discuss with selenium maintainers!

Either way, thank you for merging #2667 which should resolve this from capybara's end! It would be super helpful to see a capybara release, since many people are going to run into this problem with current selenium and capybara latest releases.

Yeah I think from selenium's perspective this was a backward-compatible change. I think they should have bumped the minor version and not the patch, but that's semantics (pun intended).

Hello! Thanks for the fix on this! This issue is also hitting us on @solidusio, and it would be great to have a new capybara version released with this fix, besides what other gems like selenium-webdriver do.

commented

i can confirm i no longer need my workaround (setting Selenium::WebDriver.logger.output) with the fix provided by #2667.

@clairity 3.39.1 was released a couple of hours before you posted -- please update