Sha256: 7b500bdd48b4d1459e81f634f8be24e37f8aa96ad2c85978a7aeccfc133642c6

Contents?: true

Size: 1.78 KB

Versions: 4

Compression:

Stored size: 1.78 KB

Contents

# FireFoxDriver specific functions for driver downloading.
class FirefoxdriverDownloader < DriverDownloader
  GECKODRIVER_URL = 'https://github.com/mozilla/geckodriver/releases/'.freeze

  def initialize(verbose = true)
    @all_driver_versions = all_driver_versions
    super(verbose)
  end

  def browser_name
    'geckodriver'
  end

  def driver_url
    GECKODRIVER_URL
  end

  def all_platforms
    %w[linux32 linux64 macos win32 win64]
  end

  # Returns the most recent version of geckodriver for the
  # desired platform.
  # platform must be one of: linux32, linux64, mac32, win32
  def latest_driver_version(platform)
    raise unknown_platform_error(platform) unless valid_platform?(platform)
    @all_driver_versions.map { |v| Gem::Version.new(v.delete('v')) }.max
  end

  # Returns all available versions of geckodriver
  def all_driver_versions
    resp = HTTParty.get(GECKODRIVER_URL, verify: false).parsed_response
    doc = Nokogiri::XML.parse(resp)
    ver_array = doc.css('div.release h1.release-title a').map(&:text)
    raise 'No versions found' if ver_array.empty?
    ver_array
  end

  # Returns the url for the desired version of geckodriver
  # version: string - must match exactly the version in the download URL
  # platform: string - must be one of: linux32, linux64, mac32, win32
  def driver_download_url(version, platform)
    raise unknown_platform_error(platform) unless valid_platform?(platform)
    raise unknown_version_error(version) unless valid_version?(version)
    extension = platform.start_with?('win') ? 'zip' : 'tar.gz'
    rel_path = "/download/v#{version}/geckodriver-v#{version}-#{platform}.#{extension}"
    "#{GECKODRIVER_URL}#{rel_path}"
  end

  def valid_version?(version)
    valid_versions = @all_driver_versions
    valid_versions.include?("v#{version}")
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chauffeur-0.0.6 lib/chauffeur/downloaders/firefoxdriver_downloader.rb
chauffeur-0.0.5 lib/chauffeur/downloaders/firefoxdriver_downloader.rb
chauffeur-0.0.4 lib/chauffeur/downloaders/firefoxdriver_downloader.rb
chauffeur-0.0.3 lib/chauffeur/downloaders/firefoxdriver_downloader.rb