Add basic send_keys implementation

This only supports simple strings, and arrays of simple strings. No
modifiers and _very_ limited symbol support (:enter and :space).
This commit is contained in:
Max Nordlund 2016-01-28 17:52:34 +01:00 committed by Matthew Horan
parent e32eb0596d
commit c226439827
3 changed files with 35 additions and 3 deletions

View File

@ -47,6 +47,21 @@ module Capybara::Webkit
invoke "set", *[value].flatten
end
def send_keys(*keys)
invoke("sendKeys", keys.map { |key|
case key
when :space
" "
when :enter
"\r"
when String
key.to_s
else
raise Capybara::NotSupportedByDriverError.new
end
}.join)
end
def select_option
invoke "selectOption"
end

View File

@ -49,9 +49,11 @@ RSpec.configure do |c|
# We can't support outerWidth and outerHeight without a visible window.
# We focus the next window instead of failing when closing windows.
# Node #send_keys is not yet implemented.
c.filter_run_excluding :full_description => lambda { |description, metadata|
description =~ /Capybara::Session webkit Capybara::Window #(size|resize_to|maximize|close.*no_such_window_error|send_keys)/ || description =~ /Capybara::Session webkit node #send_keys/
(description !~ /Capybara::Session webkit node #send_keys should send a string of keys to an element/) && (
description =~ /Capybara::Session webkit Capybara::Window #(size|resize_to|maximize|close.*no_such_window_error|send_keys)/ ||
description =~ /Capybara::Session webkit node #send_keys/
)
}
end

View File

@ -276,6 +276,20 @@ Capybara = {
return true;
},
sendKeys: function (index, keys) {
var strindex, length;
length = keys.length;
if (length) {
this.focus(index);
}
for (strindex = 0; strindex < length; strindex++) {
CapybaraInvocation.keypress(keys[strindex]);
}
},
set: function (index, value) {
var length, maxLength, node, strindex, textTypes, type;
@ -300,8 +314,9 @@ Capybara = {
CapybaraInvocation.keypress(value[strindex]);
}
if (value == '')
if (value === "") {
this.trigger(index, "change");
}
}
} else if (type === "checkbox" || type === "radio") {
if (node.checked != (value === "true")) {