Sha256: 80ea49eaeafe28b1a8b97f558185e0d2b68dec9f8048d6ea1d212bafb3fc8d7d

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

require "nokogiri"

module WebDriverManager
  class GeckoDriver
    extend Support

    class << self
      def current_binary
        WebDriverManager.logger.debug("Checking Current Driver Version")
        return nil unless driver_is_downloaded?
        binary_version = `#{driver_binary} --version`
        WebDriverManager.logger.debug(
          "Current version of #{driver_binary} is #{binary_version}"
        )
        normalize(binary_version.match(/geckodriver (\d+\.\d+\.\d+)/)[1])
      end

      def driver_name
        os_platform == "win" ? "geckodriver.exe" : "geckodriver"
      end

      def driver_base_url
        "https://github.com/mozilla/geckodriver/releases"
      end

      def driver_binary_list
        unless driver_url_is_reachable?
          raise StandardError, "Unable to Access the Driver URL"
        end

        @binaries ||= begin
          files = process_binary_files
          process_binary_versions(files)
        end
      end

      def process_binary_files
        resource = Nokogiri::XML.parse(get(driver_base_url))
        files = resource.css(".py-2 a")
                        .collect { |file| file["href"] }
        files.reject! { |file| file.include?('archive') }
        files.select! { |file| file.include?(os_platform) }
      end

      def process_binary_versions(files)
        binary_list = files.each_with_object({}) do |file, binary|
          version = normalize(file[/v(\d+\.\d+\.\d+)/, 1])
          binary[version] = "https://github.com#{file}"
        end

        WebDriverManager.logger.debug(
          "Versions Located at Driver URL: #{binary_list.keys}"
        )

        binary_list
      end

      def normalize(string)
        string.match(/(\d+)\.(\d+\.\d+)/)
              .to_a
              .map { |v| v.tr('.', '') }[1..-1].join('.').to_f
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
webdriver_manager-0.6.0 lib/webdriver_manager/drivers/driver_gecko.rb
webdriver_manager-0.5.0 lib/webdriver_manager/drivers/driver_gecko.rb
webdriver_manager-0.4.0 lib/webdriver_manager/drivers/driver_gecko.rb