class Applitools::Calabash::FullPageCaptureAlgorithm::IosUITableView

Constants

CROP_SHADOW_BOUNDS
NEXT_REQUEST_DELAY
NSSIZE

Public Class Methods

new(*args) click to toggle source
# 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

Public Instance Methods

cutted_eyes_window(side, region = eyes_window) click to toggle source
# 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_size() click to toggle source
# 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_window() click to toggle source
# 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) click to toggle source
# 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_position() click to toggle source
# 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_size() click to toggle source
# 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_position() click to toggle source
# 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) { |previous_position, is_first| ... } click to toggle source
# 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!() { |position, !is_first_vertical, !is_first_horizontal| ... } click to toggle source
# 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_top() click to toggle source
# 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_element() click to toggle source
# 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_position() click to toggle source
# 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) click to toggle source
# 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