Sha256: e991ecedf3ebb3405e6c0414f658c8ac3bc5d9b67ba3c9405ba04149a2566326

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Rspeckled
module Selenium
module Drivers
class  Chrome
  attr_reader :downloads_directory

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

  def driver(app)
    ::Capybara::Selenium::Driver.new(
      app,
      :browser              => :chrome,
      :desired_capabilities => ::Selenium::WebDriver::Remote::Capabilities.chrome(options)
    )
  end

  def headless(app)
    ::Capybara::Selenium::Driver.new(
      app,
      :browser              => :chrome,
      :desired_capabilities => ::Selenium::WebDriver::Remote::Capabilities.chrome(headless_options)
    )
  end

  private

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

    @downloads_directory = dir
  end

  def options
    {
      'chromeOptions' => {
        'prefs' => {
          'profile.default_content_settings.popups' => 0,
          'download.default_directory'              => downloads_directory,
        },
        'args'  => %w{
                     window-size=1920,1200
                   },
      },
    }
  end

  def headless_options
    options.dup.tap do |browser_options|
      browser_options['chromeOptions']['args'] << 'headless'
      browser_options['chromeOptions']['args'] << 'disable-gpu'
    end
  end
end
end
end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rspeckled-1.0.3 lib/rspeckled/selenium/drivers/chrome.rb
rspeckled-1.0.2 lib/rspeckled/selenium/drivers/chrome.rb
rspeckled-1.0.1 lib/rspeckled/selenium/drivers/chrome.rb
rspeckled-1.0.0 lib/rspeckled/selenium/drivers/chrome.rb
rspeckled-0.0.64 lib/rspeckled/selenium/drivers/chrome.rb
rspeckled-0.0.63 lib/rspeckled/selenium/drivers/chrome.rb
rspeckled-0.0.62 lib/rspeckled/selenium/drivers/chrome.rb