class Applitools::Calabash::EyesCalabashScreenshot

Constants

CONTEXT_RELATIVE
DRIVER
SCREENSHOT_AS_IS

Attributes

scale_factor[R]

Public Class Methods

new(image, options = {}) click to toggle source
Calls superclass method
# File lib/applitools/calabash/eyes_calabash_screenshot.rb, line 12
def initialize(image, options = {})
  super image
  @scale_factor = options[:scale_factor] || 1
  # return if (location = options[:location]).nil?
  # Applitools::ArgumentGuard.is_a? location, 'options[:location]', Applitools::Location
  # @bounds = Applitools::Region.new location.x, location.y, image.width, image.height
end

Public Instance Methods

convert_location(_location, _from, _to) click to toggle source
# File lib/applitools/calabash/eyes_calabash_screenshot.rb, line 57
def convert_location(_location, _from, _to)
  raise(
    Applitools::EyesError,
    'Call to :convert_location is prohibited for Applitools::Calabash::EyesCalabashScreenshot'
  )
end
intersected_region(region, from, to = CONTEXT_RELATIVE) click to toggle source
# File lib/applitools/calabash/eyes_calabash_screenshot.rb, line 48
def intersected_region(region, from, to = CONTEXT_RELATIVE)
  Applitools::ArgumentGuard.not_nil region, 'region'
  Applitools::ArgumentGuard.not_nil from, 'coordinates Type (from)'
  return Applitools::Region.new(0, 0, 0, 0) if region.empty?
  intersected_region = convert_region_location region, from, to
  intersected_region.intersect bounds
  intersected_region
end
location_in_screenshot(_location, _coordinates_type) click to toggle source
# File lib/applitools/calabash/eyes_calabash_screenshot.rb, line 41
def location_in_screenshot(_location, _coordinates_type)
  raise(
    Applitools::EyesError,
    'Call to :convert_location is prohibited for Applitools::Calabash::EyesCalabashScreenshot'
  )
end
scale_it!() click to toggle source
# File lib/applitools/calabash/eyes_calabash_screenshot.rb, line 66
def scale_it!
  width = (image.width.to_f / scale_factor).to_i
  height = (image.height.to_f / scale_factor).to_i
  image.resample_bicubic!(width, height)
  self
end
sub_screenshot(region, coordinates_type, throw_if_clipped = false, force_nil_if_clipped = false) click to toggle source
# File lib/applitools/calabash/eyes_calabash_screenshot.rb, line 20
def sub_screenshot(region, coordinates_type, throw_if_clipped = false, force_nil_if_clipped = false)
  Applitools::ArgumentGuard.not_nil region, 'region'
  Applitools::ArgumentGuard.not_nil coordinates_type, 'coordinates_type'

  sub_screen_region = intersected_region region, coordinates_type, SCREENSHOT_AS_IS

  if sub_screen_region.empty? || (throw_if_clipped && !region.size_equals?(sub_screen_region))
    return nil if force_nil_if_clipped
    raise Applitools::OutOfBoundsException, "Region #{sub_screen_region} (#{coordinates_type}) is out of " \
    " screenshot bounds #{bounds}"
  end

  sub_screenshot_image = Applitools::Screenshot.from_any_image(
    image.crop(
      sub_screen_region.left, sub_screen_region.top, sub_screen_region.width, sub_screen_region.height
    ).to_datastream.to_blob
  )

  self.class.new sub_screenshot_image, scale_factor: scale_factor
end

Private Instance Methods

bounds() click to toggle source
# File lib/applitools/calabash/eyes_calabash_screenshot.rb, line 75
def bounds
  @bounds ||= Applitools::Region.new(0, 0, image.width, image.height)
end