Sha256: 6fc5d30e2c3c406df4cdfb7a6c0792fd5f6c571804ec9bf4f789a0be48233ae5

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require 'pathname'
require "capybara/dsl"
require "capybara/poltergeist"

module Seeit
  class Screenshot
    include Capybara::DSL
    def initialize(save_path)

      @browser_width = 1024
      @browser_height = 768

      Capybara.run_server = false
      Capybara.register_driver :poltergeist do |app|
        Capybara::Poltergeist::Driver.new(app, {
          # Raise JavaScript errors to Ruby
          js_errors: false,
          # Additional command line options for PhantomJS
          phantomjs_options: ['--ignore-ssl-errors=yes', '--ssl-protocol=any']
        })
      end
      Capybara.current_driver = :poltergeist

      #@_url     = url
      #@_name    = name
      @_path    = save_path
    end

    def resize_width(width = nil)
      _width = @browser_width
      _width = width unless width.nil?
      page.driver.resize(_width, @browser_height)
    end

    def open_url(url = nil)
      @_url = url unless url.nil?
      visit @_url
    end

    def snap(name = nil)
      @_name = name unless name.nil?
      take_screenshot
    end

    private

    def take_screenshot()
      output_path = File.join @_path, "#{@_name}.png"
      save_screenshot(output_path, {full: true, gravity: 'north'})
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seeit-0.1.0 lib/seeit/screen.rb