Question

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

Was it helpful?

Solution

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!

OTHER TIPS

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
   #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
    }

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top