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

时间:2017-08-17 05:56:26

标签: android automated-tests android-testing calabash 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'")

但是当我使用这种方法时,会调用溢出按钮但不能触及其中的项目

enter image description here

2 个答案:

答案 0 :(得分:1)

尝试使用query("android.support.v7.widget.ActionMenuView")并查看您获得的元素数量,然后找出您需要的元素,可以通过'id''content-description'来识别它们。

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

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

enter image description here

现在你可以浏览那个ListView的子代,以便访问所需的东西,比如这样(在图片上面用作例子):

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

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

答案 1 :(得分:0)

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

这可以在屏幕上显示溢出菜单按钮。

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

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