2017-03-06 75 views
1

我有在Android咖啡UI测试的一个问题,当我尝试点击图像按钮:上的ImageButton的Android咖啡点击点击错误的位置

我有以下布局:

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

在我的应用程序,这看起来是这样的:

enter image description here

在我的咖啡测试我尝试一下用它的按钮(一个带箭头)

onView(withId(R.id.parent_task_button)).perform(click()); 

但点击不起作用。我踩着它通过(启用了Android的“查看水龙头”和“指针位置”开发商设置)和事实证明,这项测试并没有点击集中在图像按钮,但这里点击:

enter image description here

。 ..完全在分隔线上,但不在ImageButton的中心。

如果我用正常的按钮替换ImageButton,点击是正确的,测试工作! 有没有人知道这里有什么问题或如何解决它?

回答

2

我发现,导致问题(在ImageButton的)行:

android:rotation="90" 

如果我从图像按钮,点击是正确的中间删除此旋转。 所以我的临时解决方法是旋转drawable本身而不是按钮。

我目前也在深入研究android espresso代码,并试图在这里找到错误的代码。 似乎点击坐标的计算是错误的,因为它忽略了旋转并因此计算错误。 如果我找到任何东西,将更新这篇文章。

+0

我发现同样的问题,并创建了一个问题:https://issuetracker.google.com/issues/64758984 – duanbo1983