【发布时间】:2019-10-19 05:48:43
【问题描述】:
我正在编写 Instrumentation 测试,但无法单击我的视图。这是我的看法
<ConstraintLayout......>
<ImageView
android:id="@+id/go_to_next"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/rounded_bg"
android:rotation="180"
android:scaleType="centerInside"
android:src="@drawable/ic_back"
app:layout_constraintBottom_toBottomOf="@+id/mobile_number_edittext"
app:layout_constraintEnd_toEndOf="parent" />
</ConstraintLayout/>
我的 constraintLayout 左右两边都有 30dp 的边距。我的测试用例如下 -
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.test", appContext.packageName)
onView(withId(R.id.go_to_next)).check(matches(isDisplayingAtLeast(90)))
onView(withId(R.id.go_to_next)).perform(click())
}
它在 click() 上失败并收到一个错误 Error performing 'single click - At Coordinates: 1457, 1213 and precision: 16, 16' on view 'with id: com.test:id/go_to_next'.
如果我像 5dp 一样为 ImageView 留出边距,但如果没有边距,它就不起作用。我该如何解决?我的视图在布局中完全可见,只是它与最右边对齐。仅供参考,所有动画都已禁用
【问题讨论】:
标签: android testing automated-tests android-espresso