Class: Applitools::Calabash::EyesCalabashScreenshot

Inherits:
EyesScreenshot show all
Defined in:
lib/applitools/calabash/eyes_calabash_screenshot.rb

Constant Summary collapse

SCREENSHOT_AS_IS =
Applitools::EyesScreenshot::COORDINATE_TYPES[:screenshot_as_is].freeze
CONTEXT_RELATIVE =
Applitools::EyesScreenshot::COORDINATE_TYPES[:context_relative].freeze
DRIVER =
'DRIVER'.freeze

Constants inherited from EyesScreenshot

EyesScreenshot::COORDINATE_TYPES

Instance Attribute Summary collapse

Attributes inherited from EyesScreenshot

#image, #top_left_location

Instance Method Summary collapse

Methods inherited from EyesScreenshot

#convert_region_location, #sub_screenshots

Methods included from Helpers

#abstract_attr_accessor, #abstract_method, #env_variable, #environment_attribute, environment_variables

Constructor Details

#initialize(image, options = {}) ⇒ EyesCalabashScreenshot

Returns a new instance of EyesCalabashScreenshot.



12
13
14
15
16
17
18
# 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

Instance Attribute Details

#scale_factorObject (readonly)

Returns the value of attribute scale_factor.



10
11
12
# File 'lib/applitools/calabash/eyes_calabash_screenshot.rb', line 10

def scale_factor
  @scale_factor
end

Instance Method Details

#convert_location(_location, _from, _to) ⇒ Object

Raises:

  • (Applitools::EyesError)


57
58
59
60
61
62
# 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) ⇒ Object



48
49
50
51
52
53
54
55
# 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) ⇒ Object

Raises:

  • (Applitools::EyesError)


41
42
43
44
45
46
# 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!Object



66
67
68
69
70
71
# 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) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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