minor cleanup/improve some variable names
This commit is contained in:
parent
c66e1c4eb4
commit
2f8f15e11e
|
@ -211,11 +211,11 @@ module Capybara
|
|||
#
|
||||
# page.attach_file(locator, '/path/to/file.png')
|
||||
#
|
||||
# @overload attach_file([locator], path, **options)
|
||||
# @overload attach_file([locator], paths, **options)
|
||||
# @macro waiting_behavior
|
||||
#
|
||||
# @param [String] locator Which field to attach the file to
|
||||
# @param [String] path The path of the file that will be attached, or an array of paths
|
||||
# @param [String, Array<String>] paths The path(s) of the file(s) that will be attached, or an array of paths
|
||||
#
|
||||
# @option options [Symbol] match (Capybara.match) The matching strategy to use (:one, :first, :prefer_exact, :smart).
|
||||
# @option options [Boolean] exact (Capybara.exact) Match the exact label name/contents or accept a partial match.
|
||||
|
@ -226,16 +226,16 @@ module Capybara
|
|||
# @option options [true, Hash] make_visible A Hash of CSS styles to change before attempting to attach the file, if `true` { opacity: 1, display: 'block', visibility: 'visible' } is used (may not be supported by all drivers)
|
||||
#
|
||||
# @return [Capybara::Node::Element] The file field element
|
||||
def attach_file(locator = nil, path, make_visible: nil, **options) # rubocop:disable Style/OptionalArguments
|
||||
Array(path).each do |p|
|
||||
raise Capybara::FileNotFound, "cannot attach file, #{p} does not exist" unless File.exist?(p.to_s)
|
||||
def attach_file(locator = nil, paths, make_visible: nil, **options) # rubocop:disable Style/OptionalArguments
|
||||
Array(paths).each do |path|
|
||||
raise Capybara::FileNotFound, "cannot attach file, #{path} does not exist" unless File.exist?(path.to_s)
|
||||
end
|
||||
# Allow user to update the CSS style of the file input since they are so often hidden on a page
|
||||
if make_visible
|
||||
ff = find(:file_field, locator, options.merge(visible: :all))
|
||||
while_visible(ff, make_visible) { |el| el.set(path) }
|
||||
while_visible(ff, make_visible) { |el| el.set(paths) }
|
||||
else
|
||||
find(:file_field, locator, options).set(path)
|
||||
find(:file_field, locator, options).set(paths)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -258,7 +258,7 @@ module Capybara
|
|||
|
||||
def select_datalist_option(input, value)
|
||||
datalist_options = input.evaluate_script(DATALIST_OPTIONS_SCRIPT)
|
||||
option = datalist_options.find { |o| o.values_at('value', 'label').include?(value) }
|
||||
option = datalist_options.find { |opt| opt.values_at('value', 'label').include?(value) }
|
||||
raise ::Capybara::ElementNotFound, %(Unable to find datalist option "#{value}") unless option
|
||||
input.set(option['value'])
|
||||
rescue ::Capybara::NotSupportedByDriverError
|
||||
|
@ -295,13 +295,13 @@ module Capybara
|
|||
begin
|
||||
el = find(selector, locator, options)
|
||||
el.set(checked)
|
||||
rescue StandardError => e
|
||||
raise unless allow_label_click && catch_error?(e)
|
||||
rescue StandardError => err
|
||||
raise unless allow_label_click && catch_error?(err)
|
||||
begin
|
||||
el ||= find(selector, locator, options.merge(visible: :all))
|
||||
find(:label, for: el, visible: true).click unless el.checked? == checked
|
||||
rescue StandardError # swallow extra errors - raise original
|
||||
raise e
|
||||
raise err
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -81,10 +81,10 @@ module Capybara
|
|||
timer = Capybara::Helpers.timer(expire_in: seconds)
|
||||
begin
|
||||
yield
|
||||
rescue StandardError => e
|
||||
rescue StandardError => err
|
||||
session.raise_server_error!
|
||||
raise e unless driver.wait? && catch_error?(e, errors)
|
||||
raise e if timer.expired?
|
||||
raise err unless driver.wait? && catch_error?(err, errors)
|
||||
raise err if timer.expired?
|
||||
sleep(0.05)
|
||||
raise Capybara::FrozenInTime, 'Time appears to be frozen. Capybara does not work with libraries which freeze time, consider using time travelling instead' if timer.stalled?
|
||||
reload if session_options.automatic_reload
|
||||
|
|
|
@ -55,8 +55,8 @@ module Capybara
|
|||
#
|
||||
def text(type = nil, normalize_ws: false)
|
||||
type ||= :all unless session_options.ignore_hidden_elements || session_options.visible_text_only
|
||||
t = synchronize { type == :all ? base.all_text : base.visible_text }
|
||||
normalize_ws ? t.gsub(/[[:space:]]+/, ' ').strip : t
|
||||
txt = synchronize { type == :all ? base.all_text : base.visible_text }
|
||||
normalize_ws ? txt.gsub(/[[:space:]]+/, ' ').strip : txt
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -86,11 +86,11 @@ module Capybara
|
|||
raise ArgumentError, 'You must specify at least one CSS style' if styles.empty?
|
||||
begin
|
||||
synchronize { base.style(styles) }
|
||||
rescue NotImplementedError => e
|
||||
rescue NotImplementedError => err
|
||||
begin
|
||||
evaluate_script(STYLE_SCRIPT, *styles)
|
||||
rescue Capybara::NotSupportedByDriverError
|
||||
raise e
|
||||
raise err
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -429,8 +429,8 @@ module Capybara
|
|||
begin
|
||||
reloaded = query_scope.reload.first(@query.name, @query.locator, @query.options)
|
||||
@base = reloaded.base if reloaded
|
||||
rescue StandardError => e
|
||||
raise e unless catch_error?(e)
|
||||
rescue StandardError => err
|
||||
raise err unless catch_error?(err)
|
||||
end
|
||||
end
|
||||
self
|
||||
|
@ -440,9 +440,8 @@ module Capybara
|
|||
%(#<Capybara::Node::Element tag="#{base.tag_name}" path="#{base.path}">)
|
||||
rescue NotSupportedByDriverError
|
||||
%(#<Capybara::Node::Element tag="#{base.tag_name}">)
|
||||
rescue StandardError => e
|
||||
raise unless session.driver.invalid_element_errors.any? { |et| e.is_a?(et) }
|
||||
|
||||
rescue StandardError => err
|
||||
raise unless session.driver.invalid_element_errors.any? { |et| err.is_a?(et) }
|
||||
%(Obsolete #<Capybara::Node::Element>)
|
||||
end
|
||||
|
||||
|
|
|
@ -306,7 +306,7 @@ module Capybara
|
|||
end
|
||||
|
||||
def options_include_minimum?(opts)
|
||||
%i[count minimum between].any? { |k| opts.key?(k) }
|
||||
%i[count minimum between].any? { |key| opts.key?(key) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,8 +29,8 @@ module Capybara
|
|||
# @return [String] The text of the element
|
||||
#
|
||||
def text(_type = nil, normalize_ws: false)
|
||||
t = native.text
|
||||
normalize_ws ? t.gsub(/[[:space:]]+/, ' ').strip : t
|
||||
txt = native.text
|
||||
normalize_ws ? txt.gsub(/[[:space:]]+/, ' ').strip : txt
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -23,9 +23,9 @@ module Capybara
|
|||
|
||||
def self.wait(options, default = Capybara.default_max_wait_time)
|
||||
# if no value or nil for the :wait option is passed it should default to the default
|
||||
w = options.fetch(:wait, nil)
|
||||
w = default if w.nil?
|
||||
w || 0
|
||||
wait = options.fetch(:wait, nil)
|
||||
wait = default if wait.nil?
|
||||
wait || 0
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -69,7 +69,7 @@ module Capybara
|
|||
private
|
||||
|
||||
def count_specified?
|
||||
COUNT_KEYS.any? { |k| options.key? k }
|
||||
COUNT_KEYS.any? { |key| options.key? key }
|
||||
end
|
||||
|
||||
def count_message
|
||||
|
|
|
@ -140,7 +140,7 @@ module Capybara
|
|||
selector = if locator.is_a?(Symbol)
|
||||
Selector.all.fetch(locator) { |sel_type| raise ArgumentError, "Unknown selector type (:#{sel_type})" }
|
||||
else
|
||||
Selector.all.values.find { |s| s.match?(locator) }
|
||||
Selector.all.values.find { |sel| sel.match?(locator) }
|
||||
end
|
||||
selector || Selector.all[session_options.default_selector]
|
||||
end
|
||||
|
@ -261,9 +261,9 @@ module Capybara
|
|||
end
|
||||
|
||||
def css_from_classes(classes)
|
||||
classes = classes.group_by { |c| c.start_with? '!' }
|
||||
(classes[false].to_a.map { |c| ".#{Capybara::Selector::CSS.escape(c)}" } +
|
||||
classes[true].to_a.map { |c| ":not(.#{Capybara::Selector::CSS.escape(c.slice(1))})" }).join
|
||||
classes = classes.group_by { |cl| cl.start_with? '!' }
|
||||
(classes[false].to_a.map { |cl| ".#{Capybara::Selector::CSS.escape(cl)}" } +
|
||||
classes[true].to_a.map { |cl| ":not(.#{Capybara::Selector::CSS.escape(cl.slice(1))})" }).join
|
||||
end
|
||||
|
||||
def apply_expression_filters(expr)
|
||||
|
|
|
@ -22,10 +22,10 @@ class Capybara::RackTest::Form < Capybara::RackTest::Node
|
|||
params = make_params
|
||||
|
||||
form_element_types = %i[input select textarea]
|
||||
form_elements_xpath = XPath.generate do |x|
|
||||
xpath = x.descendant(*form_element_types).where(!x.attr(:form))
|
||||
xpath += x.anywhere(*form_element_types).where(x.attr(:form) == native[:id]) if native[:id]
|
||||
xpath.where(!x.attr(:disabled))
|
||||
form_elements_xpath = XPath.generate do |xp|
|
||||
xpath = xp.descendant(*form_element_types).where(!xp.attr(:form))
|
||||
xpath += xp.anywhere(*form_element_types).where(xp.attr(:form) == native[:id]) if native[:id]
|
||||
xpath.where(!xp.attr(:disabled))
|
||||
end.to_s
|
||||
|
||||
native.xpath(form_elements_xpath).map do |field|
|
||||
|
|
|
@ -105,11 +105,11 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
|
|||
end
|
||||
|
||||
def find_xpath(locator)
|
||||
native.xpath(locator).map { |n| self.class.new(driver, n) }
|
||||
native.xpath(locator).map { |el| self.class.new(driver, el) }
|
||||
end
|
||||
|
||||
def find_css(locator)
|
||||
native.css(locator, Capybara::RackTest::CSSHandlers.new).map { |n| self.class.new(driver, n) }
|
||||
native.css(locator, Capybara::RackTest::CSSHandlers.new).map { |el| self.class.new(driver, el) }
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
|
@ -165,7 +165,7 @@ private
|
|||
end
|
||||
|
||||
def set_radio(_value) # rubocop:disable Naming/AccessorMethodName
|
||||
other_radios_xpath = XPath.generate { |x| x.anywhere(:input)[x.attr(:name) == self[:name]] }.to_s
|
||||
other_radios_xpath = XPath.generate { |xp| xp.anywhere(:input)[xp.attr(:name) == self[:name]] }.to_s
|
||||
driver.dom.xpath(other_radios_xpath).each { |node| node.remove_attribute('checked') }
|
||||
native['checked'] = 'checked'
|
||||
end
|
||||
|
@ -185,11 +185,11 @@ private
|
|||
value = value.to_s[0...self[:maxlength].to_i]
|
||||
end
|
||||
if value.is_a?(Array) # Assert multiple attribute is present
|
||||
value.each do |v|
|
||||
value.each do |val|
|
||||
new_native = native.clone
|
||||
new_native.remove_attribute('value')
|
||||
native.add_next_sibling(new_native)
|
||||
new_native['value'] = v.to_s
|
||||
new_native['value'] = val.to_s
|
||||
end
|
||||
native.remove
|
||||
else
|
||||
|
|
|
@ -21,7 +21,7 @@ if defined?(::RSpec::Expectations::Version)
|
|||
class CapybaraEvaluator
|
||||
def initialize(actual)
|
||||
@actual = actual
|
||||
@match_results = Hash.new { |h, matcher| h[matcher] = matcher.matches?(@actual) }
|
||||
@match_results = Hash.new { |hsh, matcher| hsh[matcher] = matcher.matches?(@actual) }
|
||||
end
|
||||
|
||||
def matcher_matches?(matcher)
|
||||
|
|
|
@ -27,15 +27,15 @@ module Capybara
|
|||
|
||||
def wrap_matches?(actual)
|
||||
yield(wrap(actual))
|
||||
rescue Capybara::ExpectationNotMet => e
|
||||
@failure_message = e.message
|
||||
rescue Capybara::ExpectationNotMet => err
|
||||
@failure_message = err.message
|
||||
false
|
||||
end
|
||||
|
||||
def wrap_does_not_match?(actual)
|
||||
yield(wrap(actual))
|
||||
rescue Capybara::ExpectationNotMet => e
|
||||
@failure_message_when_negated = e.message
|
||||
rescue Capybara::ExpectationNotMet => err
|
||||
@failure_message_when_negated = err.message
|
||||
false
|
||||
end
|
||||
|
||||
|
|
|
@ -8,12 +8,12 @@ module Capybara
|
|||
out = +''
|
||||
out << value.slice!(0...1) if value =~ /^[-_]/
|
||||
out << (value[0] =~ NMSTART ? value.slice!(0...1) : escape_char(value.slice!(0...1)))
|
||||
out << value.gsub(/[^a-zA-Z0-9_-]/) { |c| escape_char c }
|
||||
out << value.gsub(/[^a-zA-Z0-9_-]/) { |char| escape_char char }
|
||||
out
|
||||
end
|
||||
|
||||
def self.escape_char(c)
|
||||
c =~ %r{[ -/:-~]} ? "\\#{c}" : format('\\%06x', c.ord)
|
||||
def self.escape_char(char)
|
||||
char =~ %r{[ -/:-~]} ? "\\#{char}" : format('\\%06x', char.ord)
|
||||
end
|
||||
|
||||
def self.split(css)
|
||||
|
@ -32,21 +32,21 @@ module Capybara
|
|||
selectors = []
|
||||
StringIO.open(css) do |str|
|
||||
selector = ''
|
||||
while (c = str.getc)
|
||||
case c
|
||||
while (char = str.getc)
|
||||
case char
|
||||
when '['
|
||||
selector += parse_square(str)
|
||||
when '('
|
||||
selector += parse_paren(str)
|
||||
when '"', "'"
|
||||
selector += parse_string(c, str)
|
||||
selector += parse_string(char, str)
|
||||
when '\\'
|
||||
selector += c + str.getc
|
||||
selector += char + str.getc
|
||||
when ','
|
||||
selectors << selector.strip
|
||||
selector = ''
|
||||
else
|
||||
selector += c
|
||||
selector += char
|
||||
end
|
||||
end
|
||||
selectors << selector.strip
|
||||
|
@ -66,16 +66,16 @@ module Capybara
|
|||
|
||||
def parse_block(start, final, strio)
|
||||
block = start
|
||||
while (c = strio.getc)
|
||||
case c
|
||||
while (char = strio.getc)
|
||||
case char
|
||||
when final
|
||||
return block + c
|
||||
return block + char
|
||||
when '\\'
|
||||
block += c + strio.getc
|
||||
block += char + strio.getc
|
||||
when '"', "'"
|
||||
block += parse_string(c, strio)
|
||||
block += parse_string(char, strio)
|
||||
else
|
||||
block += c
|
||||
block += char
|
||||
end
|
||||
end
|
||||
raise ArgumentError, "Invalid CSS Selector - Block end '#{final}' not found"
|
||||
|
@ -83,9 +83,9 @@ module Capybara
|
|||
|
||||
def parse_string(quote, strio)
|
||||
string = quote
|
||||
while (c = strio.getc)
|
||||
string += c
|
||||
case c
|
||||
while (char = strio.getc)
|
||||
string += char
|
||||
case char
|
||||
when quote
|
||||
return string
|
||||
when '\\'
|
||||
|
|
|
@ -11,7 +11,7 @@ module Capybara
|
|||
@name = name
|
||||
@node_filters = {}
|
||||
@expression_filters = {}
|
||||
@descriptions = Hash.new { |h, k| h[k] = [] }
|
||||
@descriptions = Hash.new { |hsh, key| hsh[key] = [] }
|
||||
instance_eval(&block)
|
||||
end
|
||||
|
||||
|
@ -39,11 +39,11 @@ module Capybara
|
|||
|
||||
def description(node_filters: true, expression_filters: true, **options)
|
||||
opts = options_with_defaults(options)
|
||||
d = +''
|
||||
d += undeclared_descriptions.map { |desc| desc.call(opts).to_s }.join
|
||||
d += expression_filter_descriptions.map { |desc| desc.call(opts).to_s }.join if expression_filters
|
||||
d += node_filter_descriptions.map { |desc| desc.call(opts).to_s }.join if node_filters
|
||||
d
|
||||
description = +''
|
||||
description += undeclared_descriptions.map { |desc| desc.call(opts).to_s }.join
|
||||
description += expression_filter_descriptions.map { |desc| desc.call(opts).to_s }.join if expression_filters
|
||||
description += node_filter_descriptions.map { |desc| desc.call(opts).to_s }.join if node_filters
|
||||
description
|
||||
end
|
||||
|
||||
def descriptions
|
||||
|
@ -53,7 +53,7 @@ module Capybara
|
|||
|
||||
def import(name, filters = nil)
|
||||
f_set = self.class.all[name]
|
||||
filter_selector = filters.nil? ? ->(*) { true } : ->(n, _) { filters.include? n }
|
||||
filter_selector = filters.nil? ? ->(*) { true } : ->(filter_name, _) { filters.include? filter_name }
|
||||
|
||||
expression_filters.merge!(f_set.expression_filters.select(&filter_selector))
|
||||
node_filters.merge!(f_set.node_filters.select(&filter_selector))
|
||||
|
@ -96,7 +96,7 @@ module Capybara
|
|||
def options_with_defaults(options)
|
||||
options = options.dup
|
||||
[expression_filters, node_filters].each do |filters|
|
||||
filters.select { |_n, f| f.default? }.each do |name, filter|
|
||||
filters.select { |_n, filter| filter.default? }.each do |name, filter|
|
||||
options[name] = filter.default unless options.key?(name)
|
||||
end
|
||||
end
|
||||
|
@ -104,7 +104,7 @@ module Capybara
|
|||
end
|
||||
|
||||
def add_filter(name, filter_class, *types, matcher: nil, **options, &block)
|
||||
types.each { |k| options[k] = true }
|
||||
types.each { |type| options[type] = true }
|
||||
raise 'ArgumentError', ':default option is not supported for filters with a :matcher option' if matcher && options[:default]
|
||||
if filter_class <= Filters::ExpressionFilter
|
||||
@expression_filters[name] = filter_class.new(name, matcher, block, options)
|
||||
|
|
|
@ -419,8 +419,8 @@ module Capybara
|
|||
def describe_all_expression_filters(**opts)
|
||||
expression_filters.map do |ef_name, ef|
|
||||
if ef.matcher?
|
||||
opts.keys.map do |k|
|
||||
" with #{ef_name}[#{k} => #{opts[k]}]" if ef.handles_option?(k) && !::Capybara::Queries::SelectorQuery::VALID_KEYS.include?(k)
|
||||
opts.keys.map do |key|
|
||||
" with #{ef_name}[#{key} => #{opts[key]}]" if ef.handles_option?(key) && !::Capybara::Queries::SelectorQuery::VALID_KEYS.include?(key)
|
||||
end.join
|
||||
elsif opts.key?(ef_name)
|
||||
" with #{ef_name} #{opts[ef_name]}"
|
||||
|
|
|
@ -15,8 +15,8 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
def self.load_selenium
|
||||
require 'selenium-webdriver'
|
||||
warn "Warning: You're using an unsupported version of selenium-webdriver, please upgrade." if Gem.loaded_specs['selenium-webdriver'].version < Gem::Version.new('3.5.0')
|
||||
rescue LoadError => e
|
||||
raise e if e.message !~ /selenium-webdriver/
|
||||
rescue LoadError => err
|
||||
raise err if err.message !~ /selenium-webdriver/
|
||||
raise LoadError, "Capybara's selenium driver is unable to load `selenium-webdriver`, please install the gem and add `gem 'selenium-webdriver'` to your Gemfile if you are using bundler."
|
||||
end
|
||||
|
||||
|
@ -259,10 +259,10 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
@browser&.quit
|
||||
rescue Selenium::WebDriver::Error::SessionNotCreatedError, Errno::ECONNREFUSED # rubocop:disable Lint/HandleExceptions
|
||||
# Browser must have already gone
|
||||
rescue Selenium::WebDriver::Error::UnknownError => e
|
||||
unless silenced_unknown_error_message?(e.message) # Most likely already gone
|
||||
rescue Selenium::WebDriver::Error::UnknownError => err
|
||||
unless silenced_unknown_error_message?(err.message) # Most likely already gone
|
||||
# probably already gone but not sure - so warn
|
||||
warn "Ignoring Selenium UnknownError during driver quit: #{e.message}"
|
||||
warn "Ignoring Selenium UnknownError during driver quit: #{err.message}"
|
||||
end
|
||||
ensure
|
||||
@browser = nil
|
||||
|
@ -375,7 +375,7 @@ private
|
|||
end
|
||||
|
||||
def silenced_unknown_error_message?(msg)
|
||||
silenced_unknown_error_messages.any? { |r| msg =~ r }
|
||||
silenced_unknown_error_messages.any? { |regex| msg =~ regex }
|
||||
end
|
||||
|
||||
def silenced_unknown_error_messages
|
||||
|
@ -385,9 +385,9 @@ private
|
|||
def unwrap_script_result(arg)
|
||||
case arg
|
||||
when Array
|
||||
arg.map { |e| unwrap_script_result(e) }
|
||||
arg.map { |arr| unwrap_script_result(arr) }
|
||||
when Hash
|
||||
arg.each { |k, v| arg[k] = unwrap_script_result(v) }
|
||||
arg.each { |key, value| arg[key] = unwrap_script_result(value) }
|
||||
when Selenium::WebDriver::Element
|
||||
build_node(arg)
|
||||
else
|
||||
|
|
|
@ -7,8 +7,8 @@ module Capybara::Selenium::Driver::ChromeDriver
|
|||
within_given_window(handle) do
|
||||
begin
|
||||
super
|
||||
rescue NoMethodError => e
|
||||
raise unless e.message =~ /full_screen_window/
|
||||
rescue NoMethodError => err
|
||||
raise unless err.message =~ /full_screen_window/
|
||||
bridge = browser.send(:bridge)
|
||||
result = bridge.http.call(:post, "session/#{bridge.session_id}/window/fullscreen", {})
|
||||
result['value']
|
||||
|
@ -18,8 +18,8 @@ module Capybara::Selenium::Driver::ChromeDriver
|
|||
|
||||
def resize_window_to(handle, width, height)
|
||||
super
|
||||
rescue Selenium::WebDriver::Error::UnknownError => e
|
||||
raise unless e.message =~ /failed to change window state/
|
||||
rescue Selenium::WebDriver::Error::UnknownError => err
|
||||
raise unless err.message =~ /failed to change window state/
|
||||
# Chromedriver doesn't wait long enough for state to change when coming out of fullscreen
|
||||
# and raises unnecessary error. Wait a bit and try again.
|
||||
sleep 0.5
|
||||
|
|
|
@ -22,7 +22,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|||
|
||||
def value
|
||||
if tag_name == 'select' && multiple?
|
||||
native.find_elements(:css, 'option:checked').map { |n| n[:value] || n.text }
|
||||
native.find_elements(:css, 'option:checked').map { |el| el[:value] || el.text }
|
||||
else
|
||||
native[:value]
|
||||
end
|
||||
|
@ -86,32 +86,32 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|||
native.click
|
||||
else
|
||||
scroll_if_needed do
|
||||
action_with_modifiers(keys, options) do |a|
|
||||
coords?(options) ? a.click : a.click(native)
|
||||
action_with_modifiers(keys, options) do |action|
|
||||
coords?(options) ? action.click : action.click(native)
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue StandardError => e
|
||||
if e.is_a?(::Selenium::WebDriver::Error::ElementClickInterceptedError) ||
|
||||
e.message =~ /Other element would receive the click/
|
||||
rescue StandardError => err
|
||||
if err.is_a?(::Selenium::WebDriver::Error::ElementClickInterceptedError) ||
|
||||
err.message =~ /Other element would receive the click/
|
||||
scroll_to_center
|
||||
end
|
||||
|
||||
raise e
|
||||
raise err
|
||||
end
|
||||
|
||||
def right_click(keys = [], **options)
|
||||
scroll_if_needed do
|
||||
action_with_modifiers(keys, options) do |a|
|
||||
coords?(options) ? a.context_click : a.context_click(native)
|
||||
action_with_modifiers(keys, options) do |action|
|
||||
coords?(options) ? action.context_click : action.context_click(native)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def double_click(keys = [], **options)
|
||||
scroll_if_needed do
|
||||
action_with_modifiers(keys, options) do |a|
|
||||
coords?(options) ? a.double_click : a.double_click(native)
|
||||
action_with_modifiers(keys, options) do |action|
|
||||
coords?(options) ? action.double_click : action.double_click(native)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -149,11 +149,11 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|||
end
|
||||
|
||||
def find_xpath(locator)
|
||||
native.find_elements(:xpath, locator).map { |n| self.class.new(driver, n) }
|
||||
native.find_elements(:xpath, locator).map { |el| self.class.new(driver, el) }
|
||||
end
|
||||
|
||||
def find_css(locator)
|
||||
native.find_elements(:css, locator).map { |n| self.class.new(driver, n) }
|
||||
native.find_elements(:css, locator).map { |el| self.class.new(driver, el) }
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
|
@ -312,8 +312,8 @@ private
|
|||
modifiers_up(actions, keys)
|
||||
actions.perform
|
||||
ensure
|
||||
a = driver.browser.action
|
||||
a.release_actions if a.respond_to?(:release_actions)
|
||||
act = driver.browser.action
|
||||
act.release_actions if act.respond_to?(:release_actions)
|
||||
end
|
||||
|
||||
def modifiers_down(actions, keys)
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node
|
||||
def set_file(value) # rubocop:disable Naming/AccessorMethodName
|
||||
super(value)
|
||||
rescue ::Selenium::WebDriver::Error::ExpectedError => e
|
||||
if e.message =~ /File not found : .+\n.+/m
|
||||
rescue ::Selenium::WebDriver::Error::ExpectedError => err
|
||||
if err.message =~ /File not found : .+\n.+/m
|
||||
raise ArgumentError, "Selenium < 3.14 with remote Chrome doesn't support multiple file upload"
|
||||
end
|
||||
raise
|
||||
|
|
|
@ -44,7 +44,7 @@ class Capybara::Selenium::MarionetteNode < Capybara::Selenium::Node
|
|||
|
||||
def send_keys(*args)
|
||||
# https://github.com/mozilla/geckodriver/issues/846
|
||||
return super(*args.map { |arg| arg == :space ? ' ' : arg }) if args.none? { |s| s.is_a? Array }
|
||||
return super(*args.map { |arg| arg == :space ? ' ' : arg }) if args.none? { |arg| arg.is_a? Array }
|
||||
|
||||
native.click
|
||||
actions = driver.browser.action
|
||||
|
|
|
@ -42,9 +42,9 @@ module Capybara
|
|||
@counter.increment
|
||||
begin
|
||||
@extended_app.call(env)
|
||||
rescue *@server_errors => e
|
||||
@error ||= e
|
||||
raise e
|
||||
rescue *@server_errors => err
|
||||
@error ||= err
|
||||
raise err
|
||||
ensure
|
||||
@counter.decrement
|
||||
end
|
||||
|
|
|
@ -254,7 +254,8 @@ module Capybara
|
|||
if visit_uri.relative?
|
||||
uri_base.port ||= @server.port if @server && config.always_include_port
|
||||
|
||||
visit_uri_parts = visit_uri.to_hash.delete_if { |_k, v| v.nil? }
|
||||
# TODO: Use compact when Ruby 2.4 is required
|
||||
visit_uri_parts = visit_uri.to_hash.delete_if { |_k, value| value.nil? }
|
||||
|
||||
# Useful to people deploying to a subdirectory
|
||||
# and/or single page apps where only the url fragment changes
|
||||
|
@ -675,8 +676,8 @@ module Capybara
|
|||
# @return [String] the path to which the file was saved
|
||||
#
|
||||
def save_page(path = nil)
|
||||
prepare_path(path, 'html').tap do |p|
|
||||
File.write(p, Capybara::Helpers.inject_asset_host(body, host: config.asset_host), mode: 'wb')
|
||||
prepare_path(path, 'html').tap do |p_path|
|
||||
File.write(p_path, Capybara::Helpers.inject_asset_host(body, host: config.asset_host), mode: 'wb')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -691,7 +692,7 @@ module Capybara
|
|||
# @param [String] path the path to where it should be saved
|
||||
#
|
||||
def save_and_open_page(path = nil)
|
||||
save_page(path).tap { |p| open_file(p) }
|
||||
save_page(path).tap { |s_path| open_file(s_path) }
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -706,7 +707,7 @@ module Capybara
|
|||
# @param [Hash] options a customizable set of options
|
||||
# @return [String] the path to which the file was saved
|
||||
def save_screenshot(path = nil, **options)
|
||||
prepare_path(path, 'png').tap { |p| driver.save_screenshot(p, options) }
|
||||
prepare_path(path, 'png').tap { |p_path| driver.save_screenshot(p_path, options) }
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -722,7 +723,7 @@ module Capybara
|
|||
#
|
||||
def save_and_open_screenshot(path = nil, **options)
|
||||
# rubocop:disable Lint/Debugger
|
||||
save_screenshot(path, options).tap { |p| open_file(p) }
|
||||
save_screenshot(path, options).tap { |s_path| open_file(s_path) }
|
||||
# rubocop:enable Lint/Debugger
|
||||
end
|
||||
|
||||
|
@ -822,7 +823,7 @@ module Capybara
|
|||
end
|
||||
|
||||
def prepare_path(path, extension)
|
||||
File.expand_path(path || default_fn(extension), config.save_path).tap { |p| FileUtils.mkdir_p(File.dirname(p)) }
|
||||
File.expand_path(path || default_fn(extension), config.save_path).tap { |p_path| FileUtils.mkdir_p(File.dirname(p_path)) }
|
||||
end
|
||||
|
||||
def default_fn(extension)
|
||||
|
@ -837,9 +838,9 @@ module Capybara
|
|||
def element_script_result(arg)
|
||||
case arg
|
||||
when Array
|
||||
arg.map { |e| element_script_result(e) }
|
||||
arg.map { |subarg| element_script_result(subarg) }
|
||||
when Hash
|
||||
arg.each { |k, v| arg[k] = element_script_result(v) }
|
||||
arg.each { |key, value| arg[key] = element_script_result(value) }
|
||||
when Capybara::Driver::Node
|
||||
Capybara::Node::Element.new(self, arg, nil, nil)
|
||||
else
|
||||
|
@ -881,9 +882,9 @@ module Capybara
|
|||
driver.switch_to_window handle
|
||||
return Window.new(self, handle) if yield
|
||||
end
|
||||
rescue StandardError => e
|
||||
rescue StandardError => err
|
||||
driver.switch_to_window(original_window_handle)
|
||||
raise e
|
||||
raise err
|
||||
else
|
||||
driver.switch_to_window(original_window_handle)
|
||||
raise Capybara::WindowError, 'Could not find a window matching block/lambda'
|
||||
|
|
|
@ -111,8 +111,8 @@ module Capybara
|
|||
end
|
||||
|
||||
class ReadOnlySessionConfig < SimpleDelegator
|
||||
SessionConfig::OPTIONS.each do |m|
|
||||
define_method "#{m}=" do |_|
|
||||
SessionConfig::OPTIONS.each do |option|
|
||||
define_method "#{option}=" do |_|
|
||||
raise 'Per session settings are only supported when Capybara.threadsafe == true'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue