123456789_123456789_123456789_123456789_123456789_

Module: Selenium::WebDriver::DriverExtensions::HasFileDownloads Private

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: rb/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb

Instance Method Summary

Instance Method Details

#delete_downloadable_files

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb', line 49

def delete_downloadable_files
  verify_enabled

  @bridge.delete_downloadable_files
end

#download_file(file_name, target_directory)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb', line 30

def download_file(file_name, target_directory)
  verify_enabled

  response = @bridge.download_file(file_name)
  contents = response['contents']

  File.open("#{file_name}.zip", 'wb') { |f| f << Base64.decode64(contents) }
  target_directory += '/' unless target_directory.end_with?('/')
  FileUtils.mkdir_p(target_directory)

  begin
    Zip::File.open("#{file_name}.zip") do |zip|
      zip.each { |entry| zip.extract(entry, "#{target_directory}#{file_name}") }
    end
  ensure
    FileUtils.rm_f("#{file_name}.zip")
  end
end

#downloadable_files

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb', line 24

def downloadable_files
  verify_enabled

  @bridge.downloadable_files['names']
end

#verify_enabled (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb', line 57

def verify_enabled
  return if capabilities['se:downloadsEnabled']

  raise Error::WebDriverError, 'You must enable downloads in order to work with downloadable files.'
end