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

Commit

Permalink
Support new Capybara 3 text requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Mar 13, 2018
1 parent cdac863 commit 778ec7f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions gemfiles/master.gemfile
Expand Up @@ -5,4 +5,5 @@ source "https://rubygems.org"
gem "capybara", github: "jnicklas/capybara"
gem "puma"

gem 'byebug'
gemspec path: "../"
22 changes: 20 additions & 2 deletions lib/capybara/webkit/node.rb
Expand Up @@ -6,12 +6,30 @@ def initialize(driver, base, browser)
end

def visible_text
Capybara::Helpers.normalize_whitespace(invoke("text"))
text = invoke(:text).to_s
if Capybara::VERSION.to_f < 3.0
Capybara::Helpers.normalize_whitespace(text)
else
text.gsub(/\ +/, ' ')
.gsub(/[\ \n]*\n[\ \n]*/, "\n")
.gsub(/\A[[:space:]&&[^\u00a0]]+/, "")
.gsub(/[[:space:]&&[^\u00a0]]+\z/, "")
.tr("\u00a0", ' ')
end
end
alias_method :text, :visible_text

def all_text
Capybara::Helpers.normalize_whitespace(invoke("allText"))
text = invoke(:allText)
if Capybara::VERSION.to_f < 3.0
Capybara::Helpers.normalize_whitespace(text)
else
text.gsub(/[\u200b\u200e\u200f]/, '')
.gsub(/[\ \n\f\t\v\u2028\u2029]+/, ' ')
.gsub(/\A[[:space:]&&[^\u00a0]]+/, "")
.gsub(/[[:space:]&&[^\u00a0]]+\z/, "")
.tr("\u00a0", ' ')
end
end

def [](name)
Expand Down
3 changes: 2 additions & 1 deletion spec/driver_spec.rb
Expand Up @@ -464,7 +464,8 @@ def url(path)
end

it "normalizes a node's text" do
expect(driver.find_xpath("//div[contains(@class, 'normalize')]").first.visible_text).to eq "Spaces not normalized"
expected = Capybara::VERSION.to_f < 3.0 ? 'Spaces not normalized' : 'Spaces not normalized '
expect(driver.find_xpath("//div[contains(@class, 'normalize')]").first.visible_text).to eq expected
end

it "returns all of a node's text" do
Expand Down

0 comments on commit 778ec7f

Please sign in to comment.