capybara-webkit icon indicating copy to clipboard operation
capybara-webkit copied to clipboard

Deprecation warning on normalize_whitespace with capybara >= 3.0

Open trusche opened this issue 7 years ago • 15 comments

Hi!

Since this commit on Capybara, first released with capybara 3.0.0.rc2, this deprecation warning is thrown:

DEPRECATED: Capybara::Helpers::normalize_whitespace is deprecated, please update your driver

This seems to be fixed on master in this commit. Any chance of a new release?

Thank you!

trusche avatar May 10 '18 14:05 trusche

Had the same issue during a Rails 5.2 upgrade, tracking master removed the warnings.

scarroll32 avatar May 22 '18 10:05 scarroll32

These warnings come in hundreds which is quite annoying. What's wrong with a patch release?

sbilharz avatar Jun 22 '18 09:06 sbilharz

Any news on this?

giedriusr avatar Jul 26 '18 07:07 giedriusr

Switching to the branch master should fix the issue until the next version of capybara-webkit will be released

# Gemfile
group :test do
  gem 'capybara-webkit', github: 'thoughtbot/capybara-webkit', branch: 'master'
end

Hirurg103 avatar Aug 06 '18 14:08 Hirurg103

Any time frame on the next release? Much appreciated, thanks!

derosm2 avatar Aug 06 '18 16:08 derosm2

After switching to the master branch of capybara-webkit my features started to fail with

  expected to find text "4 Total Users" in "4\nTotal\nUsers\n" (RSpec::Expectations::ExpectationNotMetError)

I decided to switch back to capybara-webkit 1.15.0 and added the following monkey-patch code to the support files to suppress the warning:

# features/support/capybara/helpers.rb
# or
# spec/support/capybara/helpers.rb
module Capybara
  module Helpers
    class << self

      alias_method :normalize_whitespace_with_warning, :normalize_whitespace

      def normalize_whitespace(*args)
        silence_warnings do
          normalize_whitespace_with_warning(*args)
        end
      end

    end
  end
end

Hirurg103 avatar Aug 07 '18 16:08 Hirurg103

@Hirurg103 Those errors are because you've updated to Capybara 3 and the master branch of capybara-webkit properly supports Capybara 3 (whereas 1.15.0 does not). The details are in Capybaras upgrade guide - https://github.com/teamcapybara/capybara/blob/master/UPGRADING.md#node. Capybara 3.5.0 also adds a normalize_ws option to the text matchers -https://github.com/teamcapybara/capybara/blob/3.5_stable/History.md#added - to mimic Capybara 2 behavior if you dont want/need to actually verify the text as displayed

twalpole avatar Aug 07 '18 18:08 twalpole

@twalpole with capybara 3.5.0 and capybara-webkit 1.15.0 I had the build green. But after switching to capybara-webkit master branch and leaving capybara version the same it started to fail with the spacing error above

Hirurg103 avatar Aug 08 '18 10:08 Hirurg103

@Hirurg103 Yes. As I stated in my comment capybara-webkit 1.5.0 does not properly support Capybara 3. It doesn't meet the Capybara 3 requirements for returning the text of an element, whereas the master branch does. The errors you get about text matching when using the master branch are correct for Capybara 3 and would be returned if you use any of the other drivers which have released Capybara 3 compliant versions.

twalpole avatar Aug 08 '18 10:08 twalpole

@twalpole Before the upgrade I used capybara 2.13.0 and capybara-webkit 1.14.0 and the build was green. After the upgrade to capybara 3.5.0 and capybara-webkit 1.15.0 the build was still green. But after switching to the master branch of capybara-webkit it started to fail. Seems like that there are breaking changes in the master branch of capybara-webkit

Hirurg103 avatar Aug 08 '18 11:08 Hirurg103

@Hirurg103 The breaking changes are from Capybara 2.x to Capybara 3.x as mentioned in the upgrade.md I linked previously - you just didn’t see them until using capybara-webkit’ master branch because capybara-webkit` 1.15 doesn’t fully support Capybara 3. I don’t know how else to explain it to you. With Capybara 3 your tests SHOULD be failing.

twalpole avatar Aug 08 '18 15:08 twalpole

@twalpole thank you for the explanation! Now I see why my build still passing after upgrade to capybara 3 and capybara webkit 1.15.

Hirurg103 avatar Aug 08 '18 15:08 Hirurg103

Here's the fix that worked for me (which @twalpole already mentioned above):

Before expect(page).to have_content(message)

After expect(page).to have_content(message, normalize_ws: true)

From my understanding, the normalize_ws flag just forces Capybara to fallback to the old way of comparing a string. Documentation

dougjohnston avatar Aug 08 '18 16:08 dougjohnston

@twalpole thanks a lot for the patience 😅 , I haven't read the Capybara upgrade guide for the first time properly

Hirurg103 avatar Aug 08 '18 16:08 Hirurg103

For now, either:

gem "capybara"
gem 'capybara-webkit', git: 'https://github.com/thoughtbot/capybara-webkit.git'

or

gem "capybara", '~>2.0'
gem 'capybara-webkit'

krisleech avatar Jul 11 '19 10:07 krisleech