Support selenium-webdriver 3.14 remote multiple upload and test remote drivers with master branch of selenium

This commit is contained in:
Thomas Walpole 2018-07-26 14:13:30 -07:00
parent 8f07330783
commit 679548cea1
5 changed files with 21 additions and 5 deletions

View File

@ -58,6 +58,16 @@ matrix:
apt:
packages:
- awesome
- gemfile: gemfiles/Gemfile.edge-marionette
rvm: ruby-head
env:
- CAPYBARA_FF=true
- CAPYBARA_REMOTE=true
- gemfile: gemfiles/Gemfile.edge-marionette
rvm: ruby-head
env:
- CAPYBARA_REMOTE=true
- HEADLESS=true
- gemfile: gemfiles/Gemfile.edge-marionette
rvm: ruby-head
env: CAPYBARA_FF=true
@ -66,6 +76,7 @@ matrix:
apt:
packages:
- awesome
- gemfile: Gemfile
rvm: 2.4.4
env: CAPYBARA_FF=true HEADLESS=true

View File

@ -5,7 +5,7 @@ class Capybara::Selenium::ChromeNode < Capybara::Selenium::Node
super(value)
rescue ::Selenium::WebDriver::Error::ExpectedError => e
if e.message =~ /File not found : .+\n.+/m
raise ArgumentError, "Selenium with remote Chrome doesn't currently support multiple file upload"
raise ArgumentError, "Selenium < 3.14 with remote Chrome doesn't support multiple file upload"
end
raise
end

View File

@ -29,6 +29,7 @@ class Capybara::Selenium::MarionetteNode < Capybara::Selenium::Node
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
# Workaround lack of support for multiple upload by uploading one at a time
path_names = value.to_s.empty? ? [] : value
Array(path_names).each do |path|
unless driver.browser.respond_to?(:upload)
@ -49,7 +50,7 @@ private
def upload(local_file)
unless File.file?(local_file)
raise Error::WebDriverError, "you may only upload files: #{local_file.inspect}"
raise ArgumentError, "You may only upload files: #{local_file.inspect}"
end
result = bridge.http.call(:post, "session/#{bridge.session_id}/file", file: Selenium::WebDriver::Zipper.zip_file(local_file))

View File

@ -30,6 +30,10 @@ def ensure_selenium_running!
end
end
def selenium_gte?(version)
defined?(Selenium::WebDriver::VERSION) && (Selenium::WebDriver::VERSION.to_f >= version)
end
Capybara.register_driver :selenium_chrome_remote do |app|
ensure_selenium_running!
@ -63,7 +67,7 @@ Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_REMOTE_DRIVER.to_s,
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"
pending "Selenium with Remote Chrome doesn't support multiple file upload" unless selenium_gte?(3.14)
end
end

View File

@ -39,14 +39,14 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
end
it 'should have return code 1 when running selenium_driver_rspec_failure.rb' do
skip if headless_or_remote?
skip "only setup for local non-headless" if headless_or_remote?
system(@env, 'rspec spec/fixtures/selenium_driver_rspec_failure.rb', out: File::NULL, err: File::NULL)
expect($CHILD_STATUS.exitstatus).to eq(1)
end
it 'should have return code 0 when running selenium_driver_rspec_success.rb' do
skip if headless_or_remote?
skip "only setup for local non-headless" if headless_or_remote?
system(@env, 'rspec spec/fixtures/selenium_driver_rspec_success.rb', out: File::NULL, err: File::NULL)
expect($CHILD_STATUS.exitstatus).to eq(0)