1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

refactor selenium driver/node

This commit is contained in:
Thomas Walpole 2018-08-24 04:45:19 -07:00
parent 194f0ae5ee
commit c8606a4c9c
2 changed files with 19 additions and 18 deletions

View file

@ -313,20 +313,23 @@ private
end
def clear_storage
if options[:clear_session_storage]
if @browser.respond_to? :session_storage
@browser.session_storage.clear
else
warn 'sessionStorage clear requested but is not available for this driver'
end
end
clear_session_storage if options[:clear_session_storage]
clear_local_storage if options[:clear_local_storage]
end
if options[:clear_local_storage] # rubocop:disable Style/GuardClause
if @browser.respond_to? :local_storage
@browser.local_storage.clear
else
warn 'localStorage clear requested but is not available for this driver'
end
def clear_session_storage
if @browser.respond_to? :session_storage
@browser.session_storage.clear
else
warn 'sessionStorage clear requested but is not available for this driver'
end
end
def clear_local_storage
if @browser.respond_to? :local_storage
@browser.local_storage.clear
else
warn 'localStorage clear requested but is not available for this driver'
end
end

View file

@ -74,12 +74,12 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
end
def select_option
native.click unless selected? || disabled?
click unless selected? || disabled?
end
def unselect_option
raise Capybara::UnselectNotAllowed, 'Cannot unselect option from single select box.' unless select_node.multiple?
native.click if selected?
click if selected?
end
def click(keys = [], **options)
@ -210,15 +210,13 @@ private
# Clear field by sending the correct number of backspace keys.
backspaces = [:backspace] * self.value.to_s.length
send_keys(*([:end] + backspaces + [value]))
elsif clear == :none
send_keys(value)
elsif clear.is_a? Array
send_keys(*clear, value)
else
# Clear field by JavaScript assignment of the value property.
# Script can change a readonly element which user input cannot, so
# don't execute if readonly.
driver.execute_script "arguments[0].value = ''", self
driver.execute_script "arguments[0].value = ''", self unless clear == :none
send_keys(value)
end
end