mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Workaround Chrome 75 appending files to file inputs
Use the same fix for Firefox since it prevents the extra change event
This commit is contained in:
parent
60d9f94fcb
commit
3819078c82
4 changed files with 23 additions and 7 deletions
|
@ -13,6 +13,14 @@ class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node
|
|||
end
|
||||
|
||||
def set_file(value) # rubocop:disable Naming/AccessorMethodName
|
||||
# In Chrome 75+ files are appended (due to WebDriver spec - why?) so we have to clear here if its multiple and already set
|
||||
if browser_version >= 75.0
|
||||
driver.execute_script(<<~JS, self)
|
||||
if (arguments[0].multiple && (arguments[0].files.length > 0)){
|
||||
arguments[0].value = null;
|
||||
}
|
||||
JS
|
||||
end
|
||||
super(value)
|
||||
rescue *file_errors => e
|
||||
raise ArgumentError, "Selenium < 3.14 with remote Chrome doesn't support multiple file upload" if e.message.match?(/File not found : .+\n.+/m)
|
||||
|
@ -58,4 +66,14 @@ private
|
|||
def bridge
|
||||
driver.browser.send(:bridge)
|
||||
end
|
||||
|
||||
def w3c?
|
||||
(defined?(Selenium::WebDriver::VERSION) && (Selenium::WebDriver::VERSION.to_f >= 4)) ||
|
||||
driver.browser.capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
|
||||
end
|
||||
|
||||
def browser_version
|
||||
caps = driver.browser.capabilities
|
||||
(caps[:browser_version] || caps[:version]).to_f
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,11 @@ class Capybara::Selenium::FirefoxNode < Capybara::Selenium::Node
|
|||
|
||||
def set_file(value) # rubocop:disable Naming/AccessorMethodName
|
||||
# By default files are appended so we have to clear here if its multiple and already set
|
||||
native.clear if multiple? && driver.evaluate_script('arguments[0].files', self).any?
|
||||
driver.execute_script(<<~JS, self)
|
||||
if (arguments[0].multiple && (arguments[0].files.length > 0)){
|
||||
arguments[0].value = null;
|
||||
}
|
||||
JS
|
||||
return super if browser_version >= 62.0
|
||||
|
||||
# Workaround lack of support for multiple upload by uploading one at a time
|
||||
|
|
|
@ -53,9 +53,6 @@ Capybara::SpecHelper.run_specs TestSessions::SeleniumFirefox, 'selenium', capyba
|
|||
pending "selenium-webdriver/geckodriver doesn't generate double click event" if firefox_lt?(59, @session)
|
||||
when 'Capybara::Session selenium #accept_prompt should accept the prompt with a blank response when there is a default'
|
||||
pending "Geckodriver doesn't set a blank response in FF < 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1486485" if firefox_lt?(63, @session)
|
||||
when 'Capybara::Session selenium #attach_file with multipart form should fire change once for each set of files uploaded'
|
||||
pending 'Gekcodriver appends files so we have to first call clear for multiple files which creates an extra change ' \
|
||||
'if files are already set'
|
||||
when 'Capybara::Session selenium #attach_file with multipart form should fire change once when uploading multiple files from empty'
|
||||
pending "FF < 62 doesn't support setting all files at once" if firefox_lt?(62, @session)
|
||||
when 'Capybara::Session selenium #accept_confirm should work with nested modals'
|
||||
|
|
|
@ -63,9 +63,6 @@ Capybara::SpecHelper.run_specs TestSessions::RemoteFirefox, FIREFOX_REMOTE_DRIVE
|
|||
skip "Firefox doesn't generate an event for shift+control+click" if firefox_gte?(62, @session)
|
||||
when 'Capybara::Session selenium_firefox_remote #accept_prompt should accept the prompt with a blank response when there is a default'
|
||||
pending "Geckodriver doesn't set a blank response in FF < 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1486485" if firefox_lt?(63, @session)
|
||||
when 'Capybara::Session selenium_firefox_remote #attach_file with multipart form should fire change once for each set of files uploaded'
|
||||
pending 'Gekcodriver appends files so we have to first call clear for multiple files which creates an extra change ' \
|
||||
'if files are already set'
|
||||
when 'Capybara::Session selenium_firefox_remote #attach_file with multipart form should fire change once when uploading multiple files from empty'
|
||||
pending "FF < 62 doesn't support setting all files at once" if firefox_lt?(62, @session)
|
||||
when 'Capybara::Session selenium_firefox_remote #reset_session! removes ALL cookies'
|
||||
|
|
Loading…
Reference in a new issue