From 09e19e305f7a67ff3152ceb1911b49d62efae5b9 Mon Sep 17 00:00:00 2001 From: Matthew Horan Date: Sun, 17 Feb 2013 23:08:53 -0500 Subject: [PATCH] Implement Node#all_text The #text method in Capybara 2.1 differentiates between visible and invisible text. This requires that Node implement #all_text. To maintain backwards compatibility with Capybara 2.0, Node#text has been aliased to #visible_text. --- lib/capybara/webkit/node.rb | 10 +++--- spec/driver_spec.rb | 71 ++++++++++++++++++++----------------- src/capybara.js | 5 +++ 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/lib/capybara/webkit/node.rb b/lib/capybara/webkit/node.rb index 57dab42..0bf37a8 100644 --- a/lib/capybara/webkit/node.rb +++ b/lib/capybara/webkit/node.rb @@ -1,10 +1,12 @@ module Capybara::Webkit class Node < Capybara::Driver::Node - NBSP = "\xC2\xA0" - NBSP.force_encoding("UTF-8") if NBSP.respond_to?(:force_encoding) + def visible_text + Capybara::Helpers.normalize_whitespace(invoke("text")) + end + alias_method :text, :visible_text - def text - invoke("text").gsub(NBSP, ' ').gsub(/\s+/u, ' ').strip + def all_text + Capybara::Helpers.normalize_whitespace(invoke("allText")) end def [](name) diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index 43f6f7b..a8a62cc 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -107,7 +107,7 @@ describe Capybara::Webkit::Driver do it "returns a node's text" do driver.within_frame("f") do - driver.find("//p").first.text.should == "goodbye" + driver.find("//p").first.visible_text.should == "goodbye" end end @@ -216,7 +216,7 @@ describe Capybara::Webkit::Driver do it "should redirect without content type" do visit("/form") driver.find("//input").first.click - driver.find("//p").first.text.should == "" + driver.find("//p").first.visible_text.should == "" end it "returns the current URL when changed by pushState after a redirect" do @@ -312,6 +312,9 @@ describe Capybara::Webkit::Driver do
Can't see me too
+
+ Some of this text is hidden! +