2018-06-06 23:11:47 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Capybara::Selenium::MarionetteNode < Capybara::Selenium::Node
|
|
|
|
def click(keys = [], **options)
|
|
|
|
super
|
|
|
|
rescue ::Selenium::WebDriver::Error::ElementNotInteractableError
|
2018-07-10 21:18:39 +00:00
|
|
|
if tag_name == 'tr'
|
|
|
|
warn 'You are attempting to click a table row which has issues in geckodriver/marionette - see https://github.com/mozilla/geckodriver/issues/1228. ' \
|
|
|
|
'Your test should probably be clicking on a table cell like a user would. Clicking the first cell in the row instead.'
|
2018-06-06 23:11:47 +00:00
|
|
|
return find_css('th:first-child,td:first-child')[0].click
|
|
|
|
end
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
|
|
|
|
def disabled?
|
2018-06-27 19:53:58 +00:00
|
|
|
# Not sure exactly what version of FF fixed the below issue, but it is definitely fixed in 61+
|
|
|
|
return super unless driver.browser.capabilities[:browser_version].to_f < 61.0
|
2018-06-06 23:11:47 +00:00
|
|
|
|
2018-06-27 19:53:58 +00:00
|
|
|
return true if super
|
2018-06-06 23:11:47 +00:00
|
|
|
# workaround for selenium-webdriver/geckodriver reporting elements as enabled when they are nested in disabling elements
|
|
|
|
if %w[option optgroup].include? tag_name
|
2018-07-10 21:18:39 +00:00
|
|
|
find_xpath('parent::*[self::optgroup or self::select]')[0].disabled?
|
2018-06-06 23:11:47 +00:00
|
|
|
else
|
2018-07-10 21:18:39 +00:00
|
|
|
!find_xpath('parent::fieldset[@disabled] | ancestor::*[not(self::legend) or preceding-sibling::legend][parent::fieldset[@disabled]]').empty?
|
2018-06-06 23:11:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_file(value) # rubocop:disable Naming/AccessorMethodName
|
|
|
|
path_names = value.to_s.empty? ? [] : value
|
|
|
|
native.clear
|
2018-06-25 23:31:31 +00:00
|
|
|
Array(path_names).each do |path|
|
|
|
|
unless driver.browser.respond_to?(:upload)
|
2018-06-26 00:27:36 +00:00
|
|
|
if (fd = bridge.file_detector)
|
2018-06-25 23:31:31 +00:00
|
|
|
local_file = fd.call([path])
|
|
|
|
path = upload(local_file) if local_file
|
|
|
|
end
|
|
|
|
end
|
|
|
|
native.send_keys(path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2018-06-26 00:27:36 +00:00
|
|
|
|
2018-06-25 23:31:31 +00:00
|
|
|
def bridge
|
|
|
|
driver.browser.send(:bridge)
|
|
|
|
end
|
|
|
|
|
|
|
|
def upload(local_file)
|
|
|
|
unless File.file?(local_file)
|
|
|
|
raise Error::WebDriverError, "you may only upload files: #{local_file.inspect}"
|
|
|
|
end
|
|
|
|
|
2018-06-26 00:27:36 +00:00
|
|
|
result = bridge.http.call(:post, "session/#{bridge.session_id}/file", file: Selenium::WebDriver::Zipper.zip_file(local_file))
|
2018-06-25 23:31:31 +00:00
|
|
|
result['value']
|
2018-06-06 23:11:47 +00:00
|
|
|
end
|
|
|
|
end
|