Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Deprecation warning on normalize_whitespace with capybara >= 3.0 #1065

Open
trusche opened this issue May 10, 2018 · 15 comments
Open

Deprecation warning on normalize_whitespace with capybara >= 3.0 #1065

trusche opened this issue May 10, 2018 · 15 comments

Comments

@trusche
Copy link

trusche commented May 10, 2018

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!

@scarroll32
Copy link

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

@sbilharz
Copy link

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

@giedriusr
Copy link

Any news on this?

@Hirurg103
Copy link

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

@derosm2
Copy link

derosm2 commented Aug 6, 2018

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

@Hirurg103
Copy link

Hirurg103 commented Aug 7, 2018

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

@twalpole
Copy link
Collaborator

twalpole commented Aug 7, 2018

@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

@Hirurg103
Copy link

@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

@twalpole
Copy link
Collaborator

twalpole commented Aug 8, 2018

@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.

@Hirurg103
Copy link

Hirurg103 commented Aug 8, 2018

@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

@twalpole
Copy link
Collaborator

twalpole commented Aug 8, 2018

@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.

@Hirurg103
Copy link

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

@dougjohnston
Copy link

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

@Hirurg103
Copy link

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

@krisleech
Copy link

For now, either:

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

or

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants