Class: Applitools::Calabash::FullPageCaptureAlgorithm::IosUITableView

Inherits:
Base
  • Object
show all
Defined in:
lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb

Constant Summary collapse

NSSIZE =
/^.*: {(?<width>\d+), (?<height>\d+)}$/
NEXT_REQUEST_DELAY =
0.5
CROP_SHADOW_BOUNDS =
5

Constants inherited from Base

Base::DEFAULT_SLEEP_INTERVAL

Instance Attribute Summary

Attributes inherited from Base

#context, #debug_screenshot_provider, #element, #screenshot_provider, #stitched_image

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ IosUITableView

Returns a new instance of IosUITableView.



13
14
15
16
17
18
19
20
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 13

def initialize(*args)
  super
  @entire_content = nil
  @stitched_image = nil
  @original_position = nil
  @entire_size = nil
  @eyes_window = nil
end

Instance Method Details

#cutted_eyes_window(side, region = eyes_window) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 51

def cutted_eyes_window(side, region = eyes_window)
  case side
  when :top
    Applitools::Region.new(
      region.left,
      region.top + CROP_SHADOW_BOUNDS,
      region.width,
      region.height - CROP_SHADOW_BOUNDS
    )
  when :left
    Applitools::Region.new(
      region.left + CROP_SHADOW_BOUNDS,
      region.top,
      region.width - CROP_SHADOW_BOUNDS,
      region.height
    )
  else
    region.dup
  end
end

#entire_sizeObject



87
88
89
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 87

def entire_size
  @entire_size ||= query_entire_size
end

#eyes_windowObject



144
145
146
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 144

def eyes_window
  @eyes_window ||= Applitools::Region.from_location_size(element.location, element.size)
end

#get_stitched_region(scroll_to_top = true) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 22

def get_stitched_region(scroll_to_top = true)
  create_entire_image
  store_original_position
  scroll_left_top if scroll_to_top

  scroll_it! do |position, cut_vertical, cut_horizontal|
    current_region = cutted_eyes_window(cut_vertical ? :top : :none)
    current_region = cutted_eyes_window(cut_horizontal ? :left : :none, current_region)

    current_position = updated_position(cut_vertical ? :top : :none, position.dup)
    current_position = updated_position(cut_horizontal ? :left : :none, current_position)

    put_it_on_canvas!(
      screenshot_provider.capture_screenshot.sub_screenshot(
        current_region,
        Applitools::Calabash::EyesCalabashScreenshot::DRIVER,
        false,
        false
      ).image.image,
      current_position.scale_it!(screenshot_provider.density)
    )
  end

  Applitools::Calabash::EyesCalabashIosScreenshot.new(
    Applitools::Screenshot.from_image(stitched_image),
    scale_factor: screenshot_provider.density
  )
end

#query_current_positionObject



98
99
100
101
102
103
104
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 98

def query_current_position
  result = Applitools::Calabash::Utils.request_element(context, element, :contentOffset).first
  Applitools::Location.new(
    result['X'].to_i,
    result['Y'].to_i
  )
end

#query_entire_sizeObject



91
92
93
94
95
96
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 91

def query_entire_size
  result = NSSIZE.match(Applitools::Calabash::Utils.request_element(context, element, :contentSize).first)
  Applitools::RectangleSize.new(
    result[:width].to_i, result[:height].to_i
  ).scale_it!(screenshot_provider.density)
end

#restore_original_positionObject



114
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 114

def restore_original_position; end

#scroll_in_one_dimension(direction, position = nil) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 124

def scroll_in_one_dimension(direction, position = nil)
  previous_position = position || query_current_position
  is_first = true
  loop do
    yield(previous_position, is_first) if block_given?
    is_first = false if is_first
    context.scroll(element.element_query, direction)
    sleep NEXT_REQUEST_DELAY
    new_position = query_current_position
    return if previous_position == new_position
    previous_position = new_position
  end
end

#scroll_it!Object



116
117
118
119
120
121
122
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 116

def scroll_it!
  scroll_in_one_dimension(:down) do |pos, is_first_vertical|
    scroll_in_one_dimension(:right, pos) do |position, is_first_horizontal|
      yield(position, !is_first_vertical, !is_first_horizontal) if block_given?
    end
  end
end

#scroll_left_topObject



138
139
140
141
142
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 138

def scroll_left_top
  scroll_in_one_dimension(:up) do |position, _is_first, _direction|
    scroll_in_one_dimension(:left, position)
  end
end

#scrollable_elementObject



83
84
85
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 83

def scrollable_element
  Applitools::Calabash::Utils.get_ios_element(context, element.element_query, 0)
end

#store_original_positionObject



106
107
108
109
110
111
112
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 106

def store_original_position
  current_scrollable_element = Applitools::Calabash::Utils.request_element(context, element, :contentSize).first
  @original_position = Applitools::Location.new(
    current_scrollable_element['X'],
    current_scrollable_element['Y']
  )
end

#updated_position(side, position) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/applitools/calabash/full_page_capture_algorithm/ios_ui_table_view.rb', line 72

def updated_position(side, position)
  case side
  when :top
    position.offset Applitools::Location.new(0, CROP_SHADOW_BOUNDS)
  when :left
    position.offset Applitools::Location.new(CROP_SHADOW_BOUNDS, 0)
  else
    position
  end
end