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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/webdrivers/common.rb', line 40

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



31
32
33
# File 'lib/webdrivers/common.rb', line 31

def latest
  downloads.keys.sort.last
end

.removeObject



35
36
37
38
# File 'lib/webdrivers/common.rb', line 35

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

.updateObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/webdrivers/common.rb', line 8

def update
  unless site_available?
    return current.nil? ? nil : binary
  end
  released = latest()
  location = binary()

  return location if released.nil? && File.exists?(binary) # Newer not found, keep current

  if released.nil? # Can't find latest and no existing binary
    msg = "Unable to find the latest version of #{file_name}; try downloading manually from #{base_url} and place in #{install_dir}"
    raise StandardError, msg
  end

  if correct_binary?
    Webdrivers.logger.debug "Expected webdriver version found"
    return location
  end

  remove # Remove outdated exe
  download # Fetch latest
end