lib/capybara/node/actions.rb in capybara-3.35.3 vs lib/capybara/node/actions.rb in capybara-3.36.0
- old
+ new
@@ -90,12 +90,13 @@
find_options[:allow_self] = true if locator.nil?
find(:fillable_field, locator, **find_options).set(with, **fill_options)
end
# @!macro label_click
- # @option options [Boolean] allow_label_click
+ # @option options [Boolean, Hash] allow_label_click
# Attempt to click the label to toggle state if element is non-visible. Defaults to {Capybara.configure automatic_label_click}.
+ # If set to a Hash it is passed as options to the `click` on the label
##
#
# Find a descendant radio button and mark it as checked. The radio button can be found
# via name, id, {Capybara.configure test_id} attribute or label text. If no locator is
@@ -275,11 +276,11 @@
# @param [String, Array<String>] paths The path(s) of the file(s) that will be attached
# @yield Block whose actions will trigger the system file chooser to be shown
# @return [Capybara::Node::Element] The file field element
def attach_file(locator = nil, paths, make_visible: nil, **options) # rubocop:disable Style/OptionalArguments
if locator && block_given?
- raise ArgumentError, '``#attach_file` does not support passing both a locator and a block'
+ raise ArgumentError, '`#attach_file` does not support passing both a locator and a block'
end
Array(paths).each do |path|
raise Capybara::FileNotFound, "cannot attach file, #{path} does not exist" unless File.exist?(path.to_s)
end
@@ -312,11 +313,11 @@
rescue Capybara::ElementNotFound => select_error # rubocop:disable Naming/RescuedExceptionsVariableName
raise if %i[selected with_selected multiple].any? { |option| options.key?(option) }
begin
find(:datalist_input, from, **options)
- rescue Capybara::ElementNotFound => dlinput_error # rubocop:disable Naming/RescuedExceptionsVariableName
+ rescue Capybara::ElementNotFound => dlinput_error
raise Capybara::ElementNotFound, "#{select_error.message} and #{dlinput_error.message}"
end
end
end
@@ -369,11 +370,15 @@
rescue StandardError => e
raise unless allow_label_click && catch_error?(e)
begin
el ||= find(selector, locator, **options.merge(visible: :all))
- el.session.find(:label, for: el, visible: true, match: :first).click unless el.checked? == checked
+ unless el.checked? == checked
+ el.session
+ .find(:label, for: el, visible: true, match: :first)
+ .click(**(Hash.try_convert(allow_label_click) || {}))
+ end
rescue StandardError # swallow extra errors - raise original
raise e
end
end
end
@@ -406,10 +411,10 @@
if (e.target.matches("input[type='file']")) {
window._capybara_clicked_file_input = e.target;
this.removeEventListener('click', file_catcher);
e.preventDefault();
}
- })
+ }, {capture: true})
JS
end
end
end