Ensure keystrokes are sent when Selenium::Node#set is passed a String for date/time fields

This commit is contained in:
Thomas Walpole 2018-05-25 09:38:13 -07:00
parent 412a308317
commit 64ce735de5
2 changed files with 10 additions and 3 deletions

View File

@ -10,6 +10,13 @@ Release date: unreleased
* New global configuration `default_set_options` used in `Capybara::Node::Element#set` as default `options` hash [Champier Cyril]
* `execute_javascript` and `evaluate_javascript` can now be called on elements to run the JS in the context of the element [Thomas Walpole]
# Version 3.1.1
Release date: unreleased
### Fixes
* Ensure keystrokes are sent when setting time/date fields to a string with the Selenium driver [Thomas Walpole]
# Version 3.1.0
Release date: 2018-05-10

View File

@ -238,19 +238,19 @@ private
end
def set_date(value) # rubocop:disable Naming/AccessorMethodName
return set_text(value) unless value.respond_to?(:to_date)
return set_text(value) if value.is_a?(String) || !value.respond_to?(:to_date)
# TODO: this would be better if locale can be detected and correct keystrokes sent
update_value_js(value.to_date.strftime('%Y-%m-%d'))
end
def set_time(value) # rubocop:disable Naming/AccessorMethodName
return set_text(value) unless value.respond_to?(:to_time)
return set_text(value) if value.is_a?(String) || !value.respond_to?(:to_time)
# TODO: this would be better if locale can be detected and correct keystrokes sent
update_value_js(value.to_time.strftime('%H:%M'))
end
def set_datetime_local(value) # rubocop:disable Naming/AccessorMethodName
return set_text(value) unless value.respond_to?(:to_time)
return set_text(value) if value.is_a?(String) || !value.respond_to?(:to_time)
# TODO: this would be better if locale can be detected and correct keystrokes sent
update_value_js(value.to_time.strftime('%Y-%m-%dT%H:%M'))
end