Sha256: b2771b449bd382f6a5b2e8979945e4780daf3c65d3806f4e8bec5f7050f99283

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require 'selenium-webdriver'
require 'aranha/selenium/driver_factory/base'

module Aranha
  module Selenium
    class DriverFactory
      class Firefox < ::Aranha::Selenium::DriverFactory::Base
        def build
          ::Selenium::WebDriver.for(
            :firefox,
            options: ::Selenium::WebDriver::Firefox::Options.new(
              profile: build_profile,
              args: build_args
            ),
            desired_capabilities: build_capabilities
          )
        end

        private

        def build_args
          r = []
          r << '-headless' if headless?
          r
        end

        def build_capabilities
          if accept_insecure_certs?
            ::Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
          else
            ::Selenium::WebDriver::Remote::Capabilities.firefox
          end
        end

        def build_profile
          r = ::Selenium::WebDriver::Firefox::Profile.new
          r['browser.download.dir'] = downloads_dir
          r['browser.download.folderList'] = 2
          r['browser.helperApps.neverAsk.saveToDisk'] = auto_download_mime_types.join(';')
          r['pdfjs.disabled'] = true
          r
        end

        def auto_download_mime_types
          ::File.read(
            ::File.join(__dir__, 'firefox_auto_download_mime_types')
          ).each_line.map(&:strip)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
aranha-0.10.1 lib/aranha/selenium/driver_factory/firefox.rb
aranha-0.10.0 lib/aranha/selenium/driver_factory/firefox.rb
aranha-0.9.1 lib/aranha/selenium/driver_factory/firefox.rb
aranha-0.9.0 lib/aranha/selenium/driver_factory/firefox.rb