Class: Webdrivers::Common

Inherits:
Object
  • Object
show all
Defined in:
lib/webdrivers/common.rb

Direct Known Subclasses

Chromedriver, Geckodriver, IEdriver, MSWebdriver

Class Method Summary collapse

Class Method Details

.download(version = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/webdrivers/common.rb', line 25

def download(version = nil)
  url = download_url(version)
  filename = File.basename url

  Dir.mkdir(install_dir) unless File.exists?(install_dir)
  Dir.chdir install_dir do
    FileUtils.rm_f filename
    open(filename, "wb") do |file|
      file.print get(url)
    end
    raise "Could not download #{url}" unless File.exists? filename
    Webdrivers.logger.debug "Successfully downloaded #{filename}"
    dcf = decompress_file(filename)
    Webdrivers.logger.debug "Decompression Complete"
    if dcf
      Webdrivers.logger.debug "Deleting #{filename}"
      FileUtils.rm_f filename
    end
    if respond_to? :extract_file
      Webdrivers.logger.debug "Extracting #{dcf}"
      extract_file(dcf)
    end
  end
  raise "Could not decompress #{filename} to get #{binary}" unless File.exists?(binary)
  FileUtils.chmod "ugo+rx", binary
  Webdrivers.logger.debug "Completed download and processing of #{binary}"
  binary
end

.latestObject



16
17
18
# File 'lib/webdrivers/common.rb', line 16

def latest
  downloads.keys.sort.last
end

.removeObject



20
21
22
23
# File 'lib/webdrivers/common.rb', line 20

def remove
  Webdrivers.logger.debug "Deleting #{binary}"
  FileUtils.rm_f binary
end

.updateObject



8
9
10
11
12
13
14
# File 'lib/webdrivers/common.rb', line 8

def update
  unless site_available?
    return current.nil? ? nil : binary
  end
  return binary if current == latest
  remove && download
end