diff --git a/lib/capybara/cuprite/node.rb b/lib/capybara/cuprite/node.rb index 6ea95b4..45c58eb 100644 --- a/lib/capybara/cuprite/node.rb +++ b/lib/capybara/cuprite/node.rb @@ -89,7 +89,7 @@ def value command(:value) end - def set(value, options = {}) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity + def set(value, options = {}) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize warn "Options passed to Node#set but Cuprite doesn't currently support any - ignoring" unless options.empty? if tag_name == "input" @@ -115,6 +115,9 @@ def set(value, options = {}) # rubocop:disable Metrics/CyclomaticComplexity, Met when "week" value = value.to_date.strftime("%G-W%V") if !value.is_a?(String) && value.respond_to?(:to_date) command(:set, value.to_s) + when "datetime-local" + value = value.to_time.strftime("%Y-%m-%dT%H:%M") if !value.is_a?(String) && value.respond_to?(:to_time) + command(:set, value.to_s) else command(:set, value.to_s) end diff --git a/spec/features/driver_spec.rb b/spec/features/driver_spec.rb index 8041d3e..23ff3b2 100644 --- a/spec/features/driver_spec.rb +++ b/spec/features/driver_spec.rb @@ -1482,6 +1482,30 @@ def create_screenshot(file, *args) expect(input.text).to eq("replacement text") end + it "sets a date field" do + input = @session.find(:css, "#date-field") + input.set(Time.new(2000, 12, 31)) + expect(input.value).to eq("2000-12-31") + end + + it "sets a datetime-local field" do + input = @session.find(:css, "#datetime-local-field") + input.set(Time.new(2000, 12, 31, 17, 15)) + expect(input.value).to eq(Time.new(2000, 12, 31, 17, 15).strftime("%Y-%m-%dT%H:%M")) + end + + it "sets a range field" do + input = @session.find(:css, "#range-field") + input.set(42) + expect(input.value).to eq("42") + end + + it "sets a color field" do + input = @session.find(:css, "#color-field") + input.set("#1270a4") + expect(input.value).to eq("#1270a4") + end + it "sets a content editable childs content" do @session.visit("/with_js") @session.find(:css, "#existing_content_editable_child").set("WYSIWYG") diff --git a/spec/support/views/set.erb b/spec/support/views/set.erb index 1e9289e..54ce9e1 100644 --- a/spec/support/views/set.erb +++ b/spec/support/views/set.erb @@ -1,10 +1,18 @@ + - + + Set tests
Content
+
+
+
+
+ +