使用NoMatchingViewException的Espresso测试失败

时间:2018-01-11 21:21:11

标签: android android-layout android-espresso

环境:Fedora 27,Android Studio 3.0.1,ConstraintLayout

我使用纵向节点中的AVD和Android Studio中的内置测试记录器设置Espresso测试。我在AVD上运行测试并成功运行。我将AVD切换为横向,Espresso测试失败。

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (with id: com.xxx.xxx:id/myButton and Child at position 11 in parent Child at position 0 in parent with id: android:id/content and is displayed on the screen to the user)

我对横向使用不同的布局,但按钮是相同的。我猜测位置编号可能与纵向布局中的位置编号不同。我想我可以为横向创建一个单独的测试,但我宁愿对两者使用相同的测试。

我想知道如何在布局中看到对象的位置编号,并且可以更改它们,以便Espresso测试可以在两个方向上运行。模式

更新1 - 19-JAN-2018 以纵向录制Espresso测试

ViewInteraction appCompatImageButton13 = onView(
    allOf(withId(R.id.buttonClear),
        childAtPosition(
            childAtPosition(
                withId(android.R.id.content),
                0),
            11),
        isDisplayed()));
appCompatImageButton13.perform(click());

以风景模式录制的测试:

ViewInteraction appCompatImageButton13 = onView(
    allOf(withId(R.id.buttonClear),
        childAtPosition(
            childAtPosition(
                withId(android.R.id.content),
                0),
            25),
        isDisplayed()));
appCompatImageButton13.perform(click());

0 个答案:

没有答案
相关问题