Class: Applitools::Selenium::FixedCutProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/applitools/selenium/fixed_cut_provider.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, header, right, footer) ⇒ FixedCutProvider

Returns a new instance of FixedCutProvider.



26
27
28
29
30
31
32
33
34
35
# File 'lib/applitools/selenium/fixed_cut_provider.rb', line 26

def initialize(left, header, right, footer)
  Applitools::ArgumentGuard.is_a?(left, 'left', Integer)
  Applitools::ArgumentGuard.is_a?(header, 'header', Integer)
  Applitools::ArgumentGuard.is_a?(right, 'right', Integer)
  Applitools::ArgumentGuard.is_a?(footer, 'footer', Integer)
  self.left = left
  self.header = header
  self.right = right
  self.footer = footer
end

Class Method Details

.viewport(image, viewport_size, region_to_check) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/applitools/selenium/fixed_cut_provider.rb', line 7

def viewport(image, viewport_size, region_to_check)
  return nil if image.square == viewport_size.square
  current_scroll_position = region_to_check.scroll_position_provider.current_position
  image_canvas = Applitools::Region.new(0, 0, image.width, image.height)
  viewport_frame = image_canvas.dup.intersect(
    Applitools::Region.from_location_size(
      Applitools::Location.new(current_scroll_position.left, current_scroll_position.top),
      viewport_size
    )
  )
  new(
    viewport_frame.left,
    viewport_frame.top,
    image_canvas.right - viewport_frame.right,
    image_canvas.bottom - viewport_frame.bottom
  )
end

Instance Method Details

#cut(image) ⇒ Object



37
38
39
40
41
# File 'lib/applitools/selenium/fixed_cut_provider.rb', line 37

def cut(image)
  crop_width = image.width - left - right
  crop_height = image.height - header - footer
  image.crop!(left, header, crop_width, crop_height)
end