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

Firefox 62 has support for multiple file uploads in one send_keys call

This commit is contained in:
Thomas Walpole 2018-07-24 14:13:03 -07:00
parent f9cacd8569
commit 7fc5d6ca14
7 changed files with 36 additions and 2 deletions

View file

@ -26,8 +26,10 @@ class Capybara::Selenium::MarionetteNode < Capybara::Selenium::Node
end
def set_file(value) # rubocop:disable Naming/AccessorMethodName
native.clear # By default files are appended so we have to clear here
return super if driver.browser.capabilities[:browser_version].to_f >= 62.0
path_names = value.to_s.empty? ? [] : value
native.clear
Array(path_names).each do |path|
unless driver.browser.respond_to?(:upload)
if (fd = bridge.file_detector)

View file

@ -168,4 +168,7 @@ $(function() {
sessionStorage.setItem('session', 'session_value');
localStorage.setItem('local', 'local value');
})
$('#multiple-file').change(function(e){
$('body').append($('<p class="file_change"input_event_triggered">File input changed</p>'));
})
});

View file

@ -94,6 +94,21 @@ Capybara::SpecHelper.spec '#attach_file' do
expect(@session.body).to include(File.read(@another_test_file_path))
expect(@session.body).not_to include(File.read(@test_file_path))
end
it 'should fire change once when uploading multiple files from empty', requires: [:js] do
@session.visit('with_js')
@session.attach_file('multiple-file',
[@test_file_path, @another_test_file_path].map { |f| with_os_path_separators(f) })
expect(@session).to have_css('.file_change', count: 1)
end
it 'should fire change once for each set of files uploaded', requires: [:js] do
@session.visit('with_js')
@session.attach_file('multiple-file', [@test_jpg_file_path].map { |f| with_os_path_separators(f) })
@session.attach_file('multiple-file',
[@test_file_path, @another_test_file_path].map { |f| with_os_path_separators(f) })
expect(@session).to have_css('.file_change', count: 2)
end
end
context "with a locator that doesn't exist" do

View file

@ -125,6 +125,10 @@
<input type="file" id="hidden_file" style="opacity:0; display: none;">
</p>
<p>
<input type="file" id="multiple-file" multiple="multiple"/>
</p>
<div id="drag_scroll">
<p>This is a draggable element.</p>
</div>

View file

@ -60,7 +60,9 @@ skipped_tests << :windows if ENV['TRAVIS'] && (ENV['SKIP_WINDOW'] || ENV['HEADLE
Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_REMOTE_DRIVER.to_s, capybara_skip: skipped_tests do |example|
case example.metadata[:full_description]
when 'Capybara::Session selenium_chrome_remote #attach_file with multipart form should not break when using HTML5 multiple file input uploading multiple files'
when 'Capybara::Session selenium_chrome_remote #attach_file with multipart form should not break when using HTML5 multiple file input uploading multiple files',
'Capybara::Session selenium_chrome_remote #attach_file with multipart form should fire change once for each set of files uploaded',
'Capybara::Session selenium_chrome_remote #attach_file with multipart form should fire change once when uploading multiple files from empty'
pending "Selenium with Remote Chrome doesn't support multiple file upload"
end
end

View file

@ -72,6 +72,9 @@ Capybara::SpecHelper.run_specs TestSessions::RemoteFirefox, FIREFOX_REMOTE_DRIVE
skip 'Firefox insists on prompting without providing a way to suppress'
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 currently"
when 'Capybara::Session selenium_firefox_remote #attach_file with multipart form should fire change once for each set of files uploaded',
'Capybara::Session selenium_firefox_remote #attach_file with multipart form should fire change once when uploading multiple files from empty'
pending 'Due to having to work around selenium remote lack of multiple file upload support the change event count is off'
end
end

View file

@ -62,6 +62,11 @@ Capybara::SpecHelper.run_specs TestSessions::SeleniumMarionette, 'selenium', cap
skip 'Firefox insists on prompting without providing a way to suppress'
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 currently"
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 marionette_lt?(62, @session)
end
end