6

I have exact same question as the post below, except that I need it to work for Android and the post below is for iOS. I have tried both solutions given in that post, but they don't seem to work for Android. All help is appreciated!

How do i scroll a UITable view down until i see a cell with label "Value" in Calabash

Community
  • 1
  • 1
Anna
  • 123
  • 1
  • 8
  • http://stackoverflow.com/questions/31120310/calabash-android-looping-through-a-listview-to-check/32471752#32471752 I have answered this question here :) – sanoop sandy Sep 09 '15 at 09:40

5 Answers5

11

you can add this new step definition and it should do the trick for Android:

Then /^I scroll until I see the "([^\"]*)" text$/ do |text|
  q = query("TextView text:'#{text}'")
  while q.empty?
    scroll_down
    q = query("TextView text:'#{text}'")
  end 
end

It works for me and I hope it does the same for you!

loeschg
  • 29,961
  • 26
  • 97
  • 150
Proghero
  • 659
  • 1
  • 9
  • 20
1

performAction('scroll_down')

In the statement, performAction() is deprecated since calabash 0.5 so not valid with the latest version

My solution will be,

def scroll_until_I_see(id)
  until element_exists("* marked:'#{id}'") do
    scroll("ScrollView", :down)
  end
end
Aravin
  • 6,605
  • 5
  • 42
  • 58
1
   #get total row count    
    count=query("ListView",:getCount).first.to_i
    var=0
    count.times {
        query("ListView",{:smoothScrollToPosition=>var})
        var+=1
        puts "#{count} #{var}"
        #break if id found  
        break if element_exists("* marked:'#{id}'")
        #fail if all rows are checked
        fail("#{id} is missing") if var==count
    }
Tejasvi Manmatha
  • 564
  • 7
  • 12
0

Here is method, it will scroll screen and return element or empty array if element not found.

def find_if_exist(text)
  query_result = query("* marked:'#{text}'")
  current_screen_state = query('*')
  prev_screen_state = []

  while (query_result.empty? and (current_screen_state != prev_screen_state))
     prev_screen_state = current_screen_state
     perform_action('drag', 50, 50, 60, 40, 20)
     current_screen_state = query('*')
     query_result = query("* marked:'#{text}'")
  end
  query_result
end
AlekseiPetrovski
  • 1,016
  • 9
  • 17
0

I have a nested view so scrolling down with scroll_down function will return "no scroll view" anyway. So based on what you all discussed I find this one working:

scroll("android.support.v4.widget.NestedScrollView",:down)

and it scrolls down, but only scrolls one time.