diff --git a/lib/capybara/cuprite/javascripts/index.js b/lib/capybara/cuprite/javascripts/index.js index 81bc8db..edbb499 100644 --- a/lib/capybara/cuprite/javascripts/index.js +++ b/lib/capybara/cuprite/javascripts/index.js @@ -124,6 +124,7 @@ class Cuprite { let valueBefore = node.value; + node.focus(); this.trigger(node, "focus"); this.setValue(node, ""); diff --git a/spec/features/driver_spec.rb b/spec/features/driver_spec.rb index a4c6685..93da041 100644 --- a/spec/features/driver_spec.rb +++ b/spec/features/driver_spec.rb @@ -1534,6 +1534,19 @@ def create_screenshot(file, *args) end end + context "input_fields" do + before { @session.visit("/cuprite/input_fields") } + + it "focuses the element when filling in the value" do + input = @session.find(:css, "#text_field") + @session.fill_in "text_field", with: "2016-02-14" + + expect(@session.find(:css, "#text_field").value).to eq("2016-02-14") + node = @session.driver.evaluate_script("document.activeElement") + expect(node).to eq input + end + end + context "evaluate_script" do it "can return an element" do @session.visit("/cuprite/send_keys") diff --git a/spec/support/views/input_fields.erb b/spec/support/views/input_fields.erb new file mode 100644 index 0000000..0836725 --- /dev/null +++ b/spec/support/views/input_fields.erb @@ -0,0 +1,9 @@ + +
+ + + + + + +