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:
parent
e32eb0596d
commit
c226439827
|
@ -47,6 +47,21 @@ module Capybara::Webkit
|
||||||
invoke "set", *[value].flatten
|
invoke "set", *[value].flatten
|
||||||
end
|
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
|
def select_option
|
||||||
invoke "selectOption"
|
invoke "selectOption"
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,9 +49,11 @@ RSpec.configure do |c|
|
||||||
|
|
||||||
# We can't support outerWidth and outerHeight without a visible window.
|
# We can't support outerWidth and outerHeight without a visible window.
|
||||||
# We focus the next window instead of failing when closing windows.
|
# 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|
|
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
|
end
|
||||||
|
|
||||||
|
|
|
@ -276,6 +276,20 @@ Capybara = {
|
||||||
return true;
|
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) {
|
set: function (index, value) {
|
||||||
var length, maxLength, node, strindex, textTypes, type;
|
var length, maxLength, node, strindex, textTypes, type;
|
||||||
|
|
||||||
|
@ -300,9 +314,10 @@ Capybara = {
|
||||||
CapybaraInvocation.keypress(value[strindex]);
|
CapybaraInvocation.keypress(value[strindex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == '')
|
if (value === "") {
|
||||||
this.trigger(index, "change");
|
this.trigger(index, "change");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (type === "checkbox" || type === "radio") {
|
} else if (type === "checkbox" || type === "radio") {
|
||||||
if (node.checked != (value === "true")) {
|
if (node.checked != (value === "true")) {
|
||||||
this.leftClick(index);
|
this.leftClick(index);
|
||||||
|
|
Loading…
Reference in New Issue