capybara-chromedriver-logger icon indicating copy to clipboard operation
capybara-chromedriver-logger copied to clipboard

Manager#logs deprecation warning after upgrading to Selenium 4.0

Open TamasGombos opened this issue 2 years ago • 14 comments

Hi!

After I updated my gemfiles to use Selenium 4.0, I received a few of these warnings: 2021-10-19 13:48:26 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.

After a few hours of research, I found out that they deprecated the use of Manager: https://github.com/SeleniumHQ/selenium/blob/trunk/rb/CHANGES#L36

The workaround for me was to remove Manage from here: https://github.com/dbalatero/capybara-chromedriver-logger/blob/60e7a9c6bc8bbe5e4dc1f508a57e5d4c6cac3d53/lib/capybara/chromedriver/logger/collector.rb#L56

After I removed it, and reran my tests, the deprecation warnings disappeared, and the console log reports were generated just fine.

I know that currently capybara-chromedriver-logger supports Selenium > 3 and Selenium < 4, but maybe for future versions it would be cool to handle this deprecation warning.

I am glad to help with more information, or anything needed. Thank you!

TamasGombos avatar Oct 19 '21 15:10 TamasGombos

Hi @TamasGombos! I see, so they moved everything from .manage up a level and got rid of it?

My issue for patching this is getting a minimal reproduction/environment to test in, so I can ensure I made the right changes. I'd rather not just blindly remove the .manage call, as it might break older clients.

Something like this could work:

def logs(type)
  browser = Capybara.current_session.driver.browser

  if browser.respond_to?(:manage)
    # Support older Selenium versions < 4
    browser.manage.logs.get(type)
  else
    # Support Selenium version 4+
    browser.logs.get(type)
  end
end

Would it be possible for you to help me get a reproduction of this warning? What could I (minimally) do in this repository to start generating this warning?

dbalatero avatar Oct 21 '21 02:10 dbalatero

Sure!

Thanks for the quick reply! On our repository, I did not change much, just regenerated the gemfile.lock with running bundle install.

Also upgraded our chromedriver and chrome versions to 94, but I don't think that is related. The only thing that got changed is Selenium, from version 3.142 to version 4.0 (that requires Ruby > 3.0).

So I would say, just try to update the gems used, run a basic test, that opens a page, and gets a loggable console error, and it should start throwing this error.

I'll try to set up the repository locally, and make an example fail. Will come back to you as soon as I have it.

TamasGombos avatar Oct 21 '21 07:10 TamasGombos

After a bit of messing around with the repository, I was able to make it work, and reproduce the issue I've got. I needed to make some changes on how we setup the browser, as selenium 4.0 has a slightly different approach.

Two of the tests failed on my setup, but that's probably because of Chrome logging level settings.

I forked the repository, you can find the reproduction branch here: https://github.com/TamasGombos/capybara-chromedriver-logger/tree/deprecation-warning-selenium-4.0

I also tried the fix you proposed, and it returned the same warning. Selenium 4.0 still supports the 'manage', so the browser responds to it.

You will need: (I used Debian Bullseye)

  • Ruby ~> 3.0
  • Selenium ~> 4.0
  • Bundler ~> 2.2

Run logs without fix:

/usr/bin/ruby2.7 -I/var/lib/gems/2.7.0/gems/rspec-support-3.10.2/lib:/var/lib/gems/2.7.0/gems/rspec-core-3.10.1/lib /var/lib/gems/2.7.0/gems/rspec-core-3.10.1/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

collector
2021-10-21 12:42:46 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  receiving no errors
2021-10-21 12:42:46 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  receiving console errors without error raising
2021-10-21 12:42:47 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  receiving console errors with error raising
2021-10-21 12:42:47 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  receiving logs with linebreaks (FAILED - 1)
2021-10-21 12:42:48 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  receiving console info logs (FAILED - 2)
2021-10-21 12:42:49 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  should ignore filtered severity types
2021-10-21 12:42:49 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  should ignore filtered messages

Run logs with branching fix:

/usr/bin/ruby2.7 -I/var/lib/gems/2.7.0/gems/rspec-support-3.10.2/lib:/var/lib/gems/2.7.0/gems/rspec-core-3.10.1/lib /var/lib/gems/2.7.0/gems/rspec-core-3.10.1/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

collector
2021-10-21 12:44:26 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  receiving no errors
2021-10-21 12:44:27 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  receiving console errors without error raising
2021-10-21 12:44:27 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  receiving console errors with error raising
2021-10-21 12:44:28 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  receiving logs with linebreaks (FAILED - 1)
2021-10-21 12:44:29 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  receiving console info logs (FAILED - 2)
2021-10-21 12:44:29 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  should ignore filtered severity types
2021-10-21 12:44:30 WARN Selenium [DEPRECATION] Manager#logs is deprecated. Use Chrome::Driver#logs instead.
  should ignore filtered messages

Run logs with .manage removal fix:

/usr/bin/ruby2.7 -I/var/lib/gems/2.7.0/gems/rspec-support-3.10.2/lib:/var/lib/gems/2.7.0/gems/rspec-core-3.10.1/lib /var/lib/gems/2.7.0/gems/rspec-core-3.10.1/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

collector
  receiving no errors
  receiving console errors without error raising
  receiving console errors with error raising
  receiving logs with linebreaks (FAILED - 1)
  receiving console info logs (FAILED - 2)
  should ignore filtered severity types
  should ignore filtered messages

TamasGombos avatar Oct 21 '21 11:10 TamasGombos

Tests produce a lot of noise. Is it possible to fix it? Screenshot from 2022-01-07 11-35-18

lazebny avatar Jan 07 '22 09:01 lazebny

@dbalatero Is there anything I can do to help? Is @rubendinho's patch mergable?

benschwarz avatar Feb 28 '22 23:02 benschwarz

The patch https://github.com/rubendinho/capybara-chromedriver-logger/commit/10632e6daa92fc849c0f92d0fb981a63e2ef750f works fine for me

lazebny avatar Mar 21 '22 10:03 lazebny

Any update to this? Could https://github.com/dbalatero/capybara-chromedriver-logger/pull/38 get merged?

reppiee avatar Jun 15 '22 01:06 reppiee

I would also love to get this fixed... Is it going to be in a near future, or can i run the patched version somehow?

parhedberg avatar Jun 22 '22 12:06 parhedberg

I would also love to get this fixed... Is it going to be in a near future, or can i run the patched version somehow?

Yes you can run a forked version like this: gem 'capybara-chromedriver-logger', git: 'https://github.com/rubendinho/capybara-chromedriver-logger'

I recommend making your own fork so your bundle doesn’t break if it’s yanked.

rubendinho avatar Jun 22 '22 13:06 rubendinho

Curious what the holdup on this is. This breaks hard in selenium-webdriver v4.4.0 (whereas deprecation warning in v4.1.0).

     Failure/Error:
       Capybara
         .current_session
         .driver.browser
         .manage
         .logs
         .get(type)

     NoMethodError:
       undefined method `logs' for #<Selenium::WebDriver::Manager:0x000000012a978238>

Happy to help or submit a sponsorship to get this across the finish line.

synth avatar Aug 28 '22 00:08 synth

Sorry, I haven't been using Rails or Capybara for 3 years now and don't have a great test setup here. I'm checking in on #38 - it can be merged, but I don't know the state of things and whether it warrants a hard major version bump since it might be a breaking API change for older clients?

dbalatero avatar Aug 28 '22 00:08 dbalatero

@dbalatero I think a major release will be a good first step.

From what you've said it might also be a good opportunity to re-home the project to another maintainer. What do you think?

benschwarz avatar Aug 29 '22 10:08 benschwarz

@dbalatero Can we rehome this repo as @benschwarz requested?

v-kumar avatar Feb 23 '23 11:02 v-kumar

Relevant to make it work with Chrome 120: https://github.com/SeleniumHQ/selenium/issues/13112. TLDR: use --headless=new instead of --headless.

tf avatar Dec 14 '23 11:12 tf