【发布时间】:2017-03-06 13:07:25
【问题描述】:
当我尝试单击图像按钮时,我在 android 上进行 espresso UI 测试时遇到问题:
我有以下布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FFFFFF">
<ImageButton
android:id="@+id/parent_task_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:rotation="90"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_subdirectory_arrow_left_black_24dp"
android:paddingRight="10dp"
android:paddingLeft="12dp"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/layout_divider"></View>
<com.mypackage.ui.TasklistItem
android:id="@+id/parent_task_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
在我的应用中是这样的:
在我的浓缩咖啡测试中,我尝试点击其中的按钮(带有箭头的那个):
onView(withId(R.id.parent_task_button)).perform(click());
但点击没有按预期工作。我逐步完成了它(启用了android“显示水龙头”和“指针位置”开发人员设置),结果证明测试没有单击以图像按钮为中心,而是单击此处:
...正好在分隔线上,但不在 ImageButton 的中心。
如果我将 ImageButton 替换为普通按钮,则单击是正确的,并且测试正常! 有谁知道这里的问题是什么或如何解决它?
【问题讨论】: