mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Merge pull request #2333 from teamcapybara/rapid_test
Respect maxlength when doing rapid set
This commit is contained in:
commit
2058fe16a5
6 changed files with 38 additions and 8 deletions
|
@ -62,6 +62,12 @@ Lint/UnusedMethodArgument:
|
|||
- 'lib/capybara/driver/base.rb'
|
||||
- 'lib/capybara/driver/node.rb'
|
||||
|
||||
Lint/RaiseException:
|
||||
Enabled: true
|
||||
|
||||
Lint/StructNewOverride:
|
||||
Enabled: true
|
||||
|
||||
Layout/EndAlignment:
|
||||
EnforcedStyleAlignWith: variable
|
||||
|
||||
|
|
|
@ -241,7 +241,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
|
||||
def quit
|
||||
@browser&.quit
|
||||
rescue Selenium::WebDriver::Error::SessionNotCreatedError, Errno::ECONNREFUSED # rubocop:disable Lint/SuppressedException
|
||||
rescue Selenium::WebDriver::Error::SessionNotCreatedError, Errno::ECONNREFUSED
|
||||
# Browser must have already gone
|
||||
rescue Selenium::WebDriver::Error::UnknownError => e
|
||||
unless silenced_unknown_error_message?(e.message) # Most likely already gone
|
||||
|
@ -293,7 +293,7 @@ private
|
|||
def clear_browser_state
|
||||
delete_all_cookies
|
||||
clear_storage
|
||||
rescue *clear_browser_state_errors # rubocop:disable Lint/SuppressedException
|
||||
rescue *clear_browser_state_errors
|
||||
# delete_all_cookies fails when we've previously gone
|
||||
# to about:blank, so we rescue this error and do nothing
|
||||
# instead.
|
||||
|
@ -317,7 +317,7 @@ private
|
|||
def clear_storage
|
||||
clear_session_storage unless options[:clear_session_storage] == false
|
||||
clear_local_storage unless options[:clear_local_storage] == false
|
||||
rescue Selenium::WebDriver::Error::JavascriptError # rubocop:disable Lint/SuppressedException
|
||||
rescue Selenium::WebDriver::Error::JavascriptError
|
||||
# session/local storage may not be available if on non-http pages (e.g. about:blank)
|
||||
end
|
||||
|
||||
|
@ -353,7 +353,7 @@ private
|
|||
@browser.navigate.to(url)
|
||||
sleep 0.1 # slight wait for alert
|
||||
@browser.switch_to.alert.accept
|
||||
rescue modal_error # rubocop:disable Lint/SuppressedException
|
||||
rescue modal_error
|
||||
# alert now gone, should mean navigation happened
|
||||
end
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ module Capybara::Selenium::Driver::W3CFirefoxDriver
|
|||
begin
|
||||
# Firefox 68 hangs if we try to switch windows while a modal is visible
|
||||
browser.switch_to.alert&.dismiss
|
||||
rescue Selenium::WebDriver::Error::NoSuchAlertError # rubocop:disable Lint/SuppressedException
|
||||
rescue Selenium::WebDriver::Error::NoSuchAlertError
|
||||
# Swallow
|
||||
end
|
||||
end
|
||||
|
@ -61,7 +61,7 @@ module Capybara::Selenium::Driver::W3CFirefoxDriver
|
|||
accept_modal :confirm, wait: 0.1 do
|
||||
super
|
||||
end
|
||||
rescue Capybara::ModalNotFound # rubocop:disable Lint/SuppressedException
|
||||
rescue Capybara::ModalNotFound
|
||||
# No modal was opened - page has refreshed - ignore
|
||||
end
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ protected
|
|||
JS
|
||||
begin
|
||||
driver.execute_script(script, self)
|
||||
rescue StandardError # rubocop:disable Lint/SuppressedException
|
||||
rescue StandardError
|
||||
# Swallow error if scrollIntoView with options isn't supported
|
||||
end
|
||||
end
|
||||
|
@ -281,7 +281,7 @@ private
|
|||
driver.execute_script 'arguments[0].select()', self unless clear == :none
|
||||
if rapid == true || (value.length > 30 && rapid != false)
|
||||
send_keys(value[0..3])
|
||||
driver.execute_script 'arguments[0].value += arguments[1]', self, value[4...-3]
|
||||
driver.execute_script RAPID_SET_TEXT, self, value[4...-3]
|
||||
send_keys(value[-3..-1])
|
||||
else
|
||||
send_keys(value)
|
||||
|
@ -530,6 +530,16 @@ private
|
|||
})(arguments[0], arguments[1], arguments[2])
|
||||
JS
|
||||
|
||||
RAPID_SET_TEXT = <<~'JS'
|
||||
(function(el, val) {
|
||||
var value = el.value + val;
|
||||
if (el.maxLength != -1){
|
||||
value = value.slice(0, el.maxLength);
|
||||
}
|
||||
el.value = value;
|
||||
})(arguments[0], arguments[1])
|
||||
JS
|
||||
|
||||
# SettableValue encapsulates time/date field formatting
|
||||
class SettableValue
|
||||
attr_reader :value
|
||||
|
|
|
@ -143,6 +143,10 @@
|
|||
<input type="text" maxlength="5" name="form[zipcode]" id="form_zipcode" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input maxlength="35" id="long_length" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="form_tendency">Tendency</label>
|
||||
<select name="form[tendency]" id="form_tendency"></select>
|
||||
|
|
|
@ -35,6 +35,16 @@ RSpec.shared_examples 'Capybara::Node' do |session, _mode|
|
|||
end
|
||||
end
|
||||
|
||||
describe '#set' do
|
||||
it 'respects maxlength when using rapid set' do
|
||||
session.visit('/form')
|
||||
inp = session.find(:css, '#long_length')
|
||||
value = (0...50).map { |i| ((i % 26) + 65).chr }.join
|
||||
inp.set(value, rapid: true)
|
||||
expect(inp.value).to eq value[0...35]
|
||||
end
|
||||
end
|
||||
|
||||
describe '#visible?' do
|
||||
let(:bridge) do
|
||||
session.driver.browser.send(:bridge)
|
||||
|
|
Loading…
Reference in a new issue