From 5843e56a8c78536b89b2be48e682ec84620ecc05 Mon Sep 17 00:00:00 2001 From: Joe Ferris Date: Fri, 30 Sep 2011 16:13:54 -0500 Subject: [PATCH] Fixed for Capybara 1.1 --- Gemfile.lock | 16 ++++++++-------- lib/capybara/driver/webkit.rb | 3 +++ lib/capybara/driver/webkit/node.rb | 10 +++++++++- src/capybara.js | 4 ++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2562ac1..71240a7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,24 +1,24 @@ GEM remote: http://rubygems.org/ specs: - capybara (1.0.0) + capybara (1.1.1) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) - selenium-webdriver (~> 0.2.0) + selenium-webdriver (~> 2.0) xpath (~> 0.1.4) - childprocess (0.1.9) + childprocess (0.2.2) ffi (~> 1.0.6) diff-lcs (1.1.2) ffi (1.0.9) - json_pure (1.5.3) + json_pure (1.6.0) mime-types (1.16) mini_magick (3.2.1) subexec (~> 0.0.4) nokogiri (1.5.0) - rack (1.3.0) - rack-test (0.6.0) + rack (1.3.2) + rack-test (0.6.1) rack (>= 1.0) rake (0.9.2) rspec (2.6.0) @@ -30,8 +30,8 @@ GEM diff-lcs (~> 1.1.2) rspec-mocks (2.6.0) rubyzip (0.9.4) - selenium-webdriver (0.2.2) - childprocess (>= 0.1.9) + selenium-webdriver (2.6.0) + childprocess (>= 0.2.1) ffi (>= 1.0.7) json_pure rubyzip diff --git a/lib/capybara/driver/webkit.rb b/lib/capybara/driver/webkit.rb index 9a2d8e6..97357b0 100644 --- a/lib/capybara/driver/webkit.rb +++ b/lib/capybara/driver/webkit.rb @@ -10,6 +10,9 @@ class Capybara::Driver::Webkit class WebkitNoResponseError < StandardError end + class NodeNotAttachedError < Capybara::ElementNotFound + end + attr_reader :browser def initialize(app, options={}) diff --git a/lib/capybara/driver/webkit/node.rb b/lib/capybara/driver/webkit/node.rb index dc293b3..9d3038f 100644 --- a/lib/capybara/driver/webkit/node.rb +++ b/lib/capybara/driver/webkit/node.rb @@ -88,7 +88,15 @@ class Capybara::Driver::Webkit end def invoke(name, *args) - browser.command "Node", name, native, *args + if attached? + browser.command "Node", name, native, *args + else + raise Capybara::Driver::Webkit::NodeNotAttachedError + end + end + + def attached? + browser.command("Node", "isAttached", native) == "true" end def browser diff --git a/src/capybara.js b/src/capybara.js index fb38191..17f2ac9 100644 --- a/src/capybara.js +++ b/src/capybara.js @@ -27,6 +27,10 @@ Capybara = { return results.join(","); }, + isAttached: function(index) { + return document.evaluate("ancestor-or-self::html", this.nodes[index], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue != null; + }, + text: function (index) { var node = this.nodes[index]; var type = (node.type || node.tagName).toLowerCase();