With Calabash for Android, how can write a step that scrolls to and touchs a specific listview row?

∥☆過路亽.° 提交于 2019-12-06 09:33:23

问题


I want to write a Cucumber step definition that scrolls to and selects a specific row in an Android ListView. On iOS I can do the following:

scroll_to_cell(:row => 1, :section => 0)
touch("tableViewCell indexPath:1,0")

How would I do the same thing on Android?

Update: In the calabash-android source, I've found a function called each_item which iterates over every item in a list view. However, I can't quite figure out how it would be valuable yet since it only returns an integer for it's position in the listview as opposed to the item itself. So, I can't do something like...

each_item do |product|
    touch(product)
end

The function lives here: https://github.com/calabash/calabash-android/blob/master/ruby-gem/lib/calabash-android/operations.rb#L145


回答1:


I can't find a general solution. Android solution will depend on ListView implementation.


The solution that will work for particular ListView is below:

1) First of all, perform query("ListView", {:getItemAtPosition => 1}) and look the property in query result that equals to the text in GUI. For instance, it can be "name".

2) Then you can touch item in specific position with the following step:

Then /^I click the (\d+)(?:st|nd|rd|th) list item$/ do |row|
  scroll_to_row("ListView", row+1)
  touch "* text:\"#{query("ListView", {:getItemAtPosition => row+1})[0]["name"]}\""  
end

I've verified it in my Android app, it works.



来源:https://stackoverflow.com/questions/23719027/with-calabash-for-android-how-can-write-a-step-that-scrolls-to-and-touchs-a-spe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!