From bbcfb7ea4b8b51be9957c78dc18f095e3c06a190 Mon Sep 17 00:00:00 2001 From: Matthew Horan Date: Tue, 8 Jul 2014 23:55:06 -0400 Subject: [PATCH] Don't interact with readonly elements * This behavior changed in Capybara 2.4. * Previously we would focus and send keypress events to readonly elements. Now readonly elements are ignored, and a warning is emitted by Capybara. --- spec/selenium_compatibility_spec.rb | 2 +- spec/spec_helper.rb | 1 + src/capybara.js | 17 +++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/spec/selenium_compatibility_spec.rb b/spec/selenium_compatibility_spec.rb index 45411b2..c4d9827 100644 --- a/spec/selenium_compatibility_spec.rb +++ b/spec/selenium_compatibility_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Capybara::Webkit, 'compatibility with selenium' do include AppRunner - it 'generates the same events as selenium when filling out forms' do + it 'generates the same events as selenium when filling out forms', selenium_compatibility: true do run_application_for_html(<<-HTML)
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7899e97..673dfa9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,6 +28,7 @@ RSpec.configure do |c| c.filter_run_excluding :skip_on_windows => !(RbConfig::CONFIG['host_os'] =~ /mingw32/).nil? c.filter_run_excluding :skip_on_jruby => !defined?(::JRUBY_VERSION).nil? + c.filter_run_excluding :selenium_compatibility => (Capybara::VERSION =~ /^2\.4\./).nil? # We can't support outerWidth and outerHeight without a visible window. # We focus the next window instead of failing when closing windows. diff --git a/src/capybara.js b/src/capybara.js index 965fa7b..359faf5 100644 --- a/src/capybara.js +++ b/src/capybara.js @@ -272,8 +272,6 @@ Capybara = { textTypes = ["email", "number", "password", "search", "tel", "text", "textarea", "url"]; if (textTypes.indexOf(type) != -1) { - this.focus(index); - maxLength = this.attribute(index, "maxlength"); if (maxLength && value.length > maxLength) { length = maxLength; @@ -281,15 +279,18 @@ Capybara = { length = value.length; } - if (!node.readOnly) + if (!node.readOnly) { + this.focus(index); + node.value = ""; - for (strindex = 0; strindex < length; strindex++) { - CapybaraInvocation.keypress(value[strindex]); - } + for (strindex = 0; strindex < length; strindex++) { + CapybaraInvocation.keypress(value[strindex]); + } - if (value == '') - this.trigger(index, "change"); + if (value == '') + this.trigger(index, "change"); + } } else if (type === "checkbox" || type === "radio") { if (node.checked != (value === "true")) { this.leftClick(index);