Method: Calabash::Android::Operations#scroll

Defined in:
lib/calabash-android/operations.rb

#scroll(query_string, direction) ⇒ Object



812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
# File 'lib/calabash-android/operations.rb', line 812

def scroll(query_string, direction)
  if direction != :up && direction != :down
    raise 'Only upwards and downwards scrolling is supported for now'
  end

  scroll_x = 0
  scroll_y = 0

  action = lambda do
    element = query(query_string).first
    raise "No elements found. Query: #{query_string}" if element.nil?

    width = element['rect']['width']
    height = element['rect']['height']

    if direction == :up
      scroll_y = -height/2
    else
      scroll_y = height/2
    end

    query(query_string, {scrollBy: [scroll_x.to_i, scroll_y.to_i]})
  end

  when_element_exists(query_string, action: action)
end