Sha256: fc142e7cddfcee6f0ee557850c7b7f2af3c4e3d91c4f9e21b576b3a5dd20cd80

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 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,
      :options => options
    )
  end

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

  private

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

    @downloads_directory = dir
  end

  def options
    browser_options = ::Selenium::WebDriver::Chrome::Options.new
    browser_options.add_preference(:profile, :prompt_for_download => { :popups => 0 })
    browser_options.add_preference(:download, :default_directory => downloads_directory)
    browser_options.add_argument('--window-size=1920,1200')
    browser_options
  end

  def headless_options
    options.dup.tap do |browser_options|
      browser_options.add_argument('--headless')
      browser_options.add_argument('--disable-gpu')
    end
  end
end
end
end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rspeckled-2.0.1 lib/rspeckled/plugins/extensions/selenium/drivers/chrome.rb
rspeckled-2.0.0 lib/rspeckled/plugins/extensions/selenium/drivers/chrome.rb
rspeckled-1.4.0 lib/rspeckled/plugins/extensions/selenium/drivers/chrome.rb