Sha256: aa8824ec5765002305f4be60ac1b342cc58d3756975429b19f94d22446a2a442

Contents?: true

Size: 981 Bytes

Versions: 1

Compression:

Stored size: 981 Bytes

Contents

require_relative 'image_wrangler'

module Gatling
  class CaptureElement

  include ImageWrangler

    def initialize element_to_capture, *element_to_exclude
      @reference_image_path = Gatling::Configuration.reference_image_path
      @element_to_capture = element_to_capture
      # @element_to_exclude = element_to_exclude.first

    end

    def capture
      screenshot = self.take_screenshot
      screenshot = exclude(screenshot, @element_to_exclude) if @element_to_exclude
      Gatling::ImageWrangler.crop_element(screenshot, @element_to_capture)
    end

    def take_screenshot
      temp_dir = "#{@reference_image_path}/temp"
      #captures the uncropped full screen
      begin
        Capybara.page.driver.browser.save_screenshot("#{temp_dir}/temp.png")
        temp_screenshot = Magick::Image.read("#{temp_dir}/temp.png").first
      rescue
        raise "Could not save screenshot to #{temp_dir}. Please make sure you have permission"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gatling-1.0.8 lib/gatling/capture_element.rb