Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/capybara/cuprite/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
24 changes: 24 additions & 0 deletions spec/features/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,30 @@ def create_screenshot(file, *args)
expect(input.text).to eq("replacement text")
end

it "sets a date field" do
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to leave these in as there wasn't test coverage, even though support for setting most of these has already been added upstream.

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")
Expand Down
10 changes: 9 additions & 1 deletion spec/support/views/set.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Set tests</title>
</head>

<body>
<div id="empty_div" contenteditable="true"></div>
<div id="filled_div" contenteditable="true">Content</div>
<form>
<input id="date-field" type="date" name="date-field"><br>
<input id="datetime-local-field" type="datetime-local" name="datetime-local-field"><br>
<input id="range-field" type="range" min="0" max="100" name="range-field"><br>
<input id="color-field" type="color" name="color-field">
</form>
</body>
</html>
Loading