thoughtbot / capybara-webkit

A Capybara driver for headless WebKit to test JavaScript web apps
https://thoughtbot.com/open-source
MIT License
1.97k stars 426 forks source link

Deprecation warning on normalize_whitespace with capybara >= 3.0 #1065

Open trusche opened 6 years ago

trusche commented 6 years ago

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 commented 6 years ago

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

sbilharz commented 6 years ago

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

giedriusr commented 6 years ago

Any news on this?

Hirurg103 commented 6 years ago

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 commented 6 years ago

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

Hirurg103 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

@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 becausecapybara-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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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

krisleech commented 5 years ago

For now, either:

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

or

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