有了Calabash for Android,如何编写一个滚动到和触摸一个特定的listview行的步骤? [英] With Calabash for Android, how can write a step that scrolls to and touchs a specific listview row?

查看:246
本文介绍了有了Calabash for Android,如何编写一个滚动到和触摸一个特定的listview行的步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个Cucumber步骤定义,滚动到并选择Android ListView中的特定行。在iOS上,我可以执行以下操作:

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")

Android?

更新:在calabash-android源代码中,我发现了一个名为each_item的函数, 。但是,我不能弄清楚它如何有价值,因为它只返回一个整数在列表视图中的位置,而不是项目本身。所以,我不能做像... ...

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

=https://github.com/calabash/calabash-android/blob/master/ruby-gem/lib/calabash-android/operations.rb#L145 =nofollow> https://github.com/ calabash / calabash-android / blob / master / ruby​​-gem / lib / calabash-android / operations.rb#L145

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

推荐答案

我找不到一个一般的解决方案。

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

适用于特定ListView的解决方案如下:

The solution that will work for particular ListView is below:

1)首先,执行 query(ListView,{:getItemAtPosition => 1})查询结果等于GUI中的文本。例如,它可以是name

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)然后您可以在特定位置触摸项目

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

app,it works。

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

这篇关于有了Calabash for Android,如何编写一个滚动到和触摸一个特定的listview行的步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆