【问题标题】:With Calabash for Android, how can write a step that scrolls to and touchs a specific listview row?使用 Calabash for Android,如何编写滚动到特定列表视图行并触摸特定列表视图行的步骤?
【发布时间】:2014-06-16 03:44:15
【问题描述】:

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

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

我如何在 Android 上做同样的事情?

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

each_item do |product|
    touch(product)
end

函数在这里:https://github.com/calabash/calabash-android/blob/master/ruby-gem/lib/calabash-android/operations.rb#L145

【问题讨论】:

    标签: android cucumber calabash


    【解决方案1】:

    我找不到通用解决方案。 Android 解决方案将依赖于 ListView 实现。


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

    1) 首先,执行query("ListView", {:getItemAtPosition => 1}) 并查看查询结果中与GUI 中文本相同的属性。例如,它可以是"name"

    2) 然后您可以通过以下步骤触摸特定位置的项目:

    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
    

    我已经在我的 Android 应用中验证了它,它可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      • 1970-01-01
      相关资源
      最近更新 更多