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

Included in:
Remote::Driver
Defined in:
rb/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#delete_downloadable_filesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
58
59
# File 'rb/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb', line 55

def delete_downloadable_files
  verify_enabled

  @bridge.delete_downloadable_files
end

#download_file(file_name, target_directory) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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 do |entry|
        if Zipper::RUBYZIP_V3
          zip.extract(entry, file_name, destination_directory: target_directory)
        else
          zip.extract(entry, "#{target_directory}#{file_name}")
        end
      end
    end
  ensure
    FileUtils.rm_f("#{file_name}.zip")
  end
end

#downloadable_filesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
# File 'rb/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb', line 24

def downloadable_files
  verify_enabled

  @bridge.downloadable_files['names']
end