Sha256: 951e209d9087b16e7b9036611267b96de1ad6ea2b7db8f76b30f561dff13cefd

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module Rspeckled
module Selenium
module Drivers
class  Firefox
  attr_reader :downloads_directory

  def initialize(options)
    self.downloads_directory = options.fetch(:downloads_directory)
  end

  def driver(app)
    ::Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile, :options => options)
  end

  def headless(app)
    ::Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile, :options => headless_options)
  end

  private

  def downloads_directory=(dir)
    ::Dir.mkdir(dir) unless ::Dir.exist?(dir)

    @downloads_directory = dir
  end

  def profile
    ::Selenium::WebDriver::Firefox::Profile.new.tap do |profile|
      profile['browser.download.dir']                   = downloads_directory
      profile['browser.download.folderList']            = 2
      profile['browser.helperApps.neverAsk.saveToDisk'] = 'images/jpeg, application/pdf, application/octet-stream'
      profile['pdfjs.disabled']                         = true
    end
  end

  def options
    ::Selenium::WebDriver::Firefox::Options.new
  end

  def headless_options
    options.dup.tap do |browser_options|
      browser_options.args << '--headless'
    end
  end
end
end
end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rspeckled-1.3.1 lib/rspeckled/plugins/extensions/selenium/drivers/firefox.rb
rspeckled-1.3.0 lib/rspeckled/plugins/extensions/selenium/drivers/firefox.rb
rspeckled-1.2.1 lib/rspeckled/plugins/extensions/selenium/drivers/firefox.rb
rspeckled-1.2.0 lib/rspeckled/plugins/extensions/selenium/drivers/firefox.rb
rspeckled-1.1.3 lib/rspeckled/plugins/extensions/selenium/drivers/firefox.rb
rspeckled-1.1.2 lib/rspeckled/plugins/extensions/selenium/drivers/firefox.rb
rspeckled-1.1.1 lib/rspeckled/plugins/extensions/selenium/drivers/firefox.rb
rspeckled-1.1.0 lib/rspeckled/plugins/extensions/selenium/drivers/firefox.rb
rspeckled-1.0.5 lib/rspeckled/plugins/extensions/selenium/drivers/firefox.rb
rspeckled-1.0.4 lib/rspeckled/plugins/extensions/selenium/drivers/firefox.rb