mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
fix: move caret even with clear backspace (#2066)
fix: move caret even with clear backspace
This commit is contained in:
parent
d2326b9568
commit
1a5f290ee1
2 changed files with 16 additions and 1 deletions
|
@ -205,7 +205,7 @@ private
|
||||||
elsif clear == :backspace
|
elsif clear == :backspace
|
||||||
# Clear field by sending the correct number of backspace keys.
|
# Clear field by sending the correct number of backspace keys.
|
||||||
backspaces = [:backspace] * self.value.to_s.length
|
backspaces = [:backspace] * self.value.to_s.length
|
||||||
native.send_keys(*(backspaces + [value.to_s]))
|
native.send_keys(*([:end] + backspaces + [value.to_s]))
|
||||||
elsif clear == :none
|
elsif clear == :none
|
||||||
native.send_keys(value.to_s)
|
native.send_keys(value.to_s)
|
||||||
elsif clear.is_a? Array
|
elsif clear.is_a? Array
|
||||||
|
|
|
@ -93,6 +93,21 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
|
||||||
expect(session.find(:fillable_field, 'form_first_name').value).to eq('Harry')
|
expect(session.find(:fillable_field, 'form_first_name').value).to eq('Harry')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should fill in a field, replacing an existing value, even with caret position' do
|
||||||
|
session.visit('/form')
|
||||||
|
el = session.find(:css, '#form_first_name')
|
||||||
|
move_caret_to_the_beginning_js = <<-JS
|
||||||
|
this.focus();
|
||||||
|
this.setSelectionRange(0, 0);
|
||||||
|
JS
|
||||||
|
el.execute_script(move_caret_to_the_beginning_js)
|
||||||
|
|
||||||
|
session.fill_in('form_first_name',
|
||||||
|
with: 'Harry',
|
||||||
|
fill_options: { clear: :backspace })
|
||||||
|
expect(session.find(:fillable_field, 'form_first_name').value).to eq('Harry')
|
||||||
|
end
|
||||||
|
|
||||||
it 'should fill in if the option is set via global option' do
|
it 'should fill in if the option is set via global option' do
|
||||||
Capybara.default_set_options = { clear: :backspace }
|
Capybara.default_set_options = { clear: :backspace }
|
||||||
session.visit('/form')
|
session.visit('/form')
|
||||||
|
|
Loading…
Add table
Reference in a new issue