如何触摸 calabash-android 中的溢出按钮?

How to touch the overflow button in calabash-android?

我正在尝试使用 calabash-android 测试来触摸我应用程序中的溢出按钮。经过大量研究,我找到了一种触摸溢出按钮的方法。

tap_when_element_exists("android.support.v7.widget.ActionMenuView")

当屏幕上只有一个溢出按钮而没有其他按钮时,这对我有用。但是对于像下图这样有溢出按钮和其他按钮的屏幕,上面的方法是行不通的。我也尝试使用索引,

tap_when_element_exists("android.support.v7.widget.ActionMenuView index:0"),
tap_when_element_exists("android.support.v7.widget.ActionMenuView index:1")

,等等,但仍未解决。

然后我用了这个方法-

select_options_menu_item("* id:'action_change_notification'")

但是当我使用这个方法时,溢出按钮被调用但无法触摸其中的项目

尝试使用 query("android.support.v7.widget.ActionMenuView") 并查看您获得了多少元素,然后确定您需要的元素,可能是 'id''content-description',这应该是唯一的。

您可以尝试使用 Android SDK 中的 uiautomator。这是识别元素和查看层次结构的非常有用的工具。

通常位于 \tools\bin 下的 sdk 文件夹中。你会看到这样的东西:

现在您可以遍历该 ListView 的子项以访问所需内容,如下所示(以上图为例):

query("android.widget.ListView android.widget.LinearLayout id:'title'")

如果有效请告诉我,可能还有其他方法。

我找到了更好的解决方案。而且效果很好。

这可以在屏幕上为您提供溢出菜单按钮。

query("android.support.v7.widget.ActionMenuPresenter$OverflowMenuButton")

tap_when_element_exists("android.support.v7.widget.ActionMenuPresenter$OverflowMenuButton")