Sha256: ca5c5a8e727f625686d6f7b47a0fe45c15f12ffe233dce51d465df3cd2da3b06

Contents?: true

Size: 1.3 KB

Versions: 10

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

10 entries across 10 versions & 1 rubygems

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