意式浓缩咖啡测试仅在第一次通过.然后由于NoMatchingViewException而不断失败 [英] Espresso test is passed only first time. Then is failed constantly because of NoMatchingViewException

查看:105
本文介绍了意式浓缩咖啡测试仅在第一次通过.然后由于NoMatchingViewException而不断失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android Studio中工作.我目前正在使用Espresso 2.1进行自动化测试创建:

I work in Android Studio. I'm currently working on automation tests creation using Espresso 2.1:

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'

我的MainActivity类具有以下xml布局:

I have following xml layout for MainActivity class:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity">

<com.esri.android.map.MapView
    android:id="@+id/mapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:contentDescription="theMainMapViewFirst">
</com.esri.android.map.MapView>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="wrap_content" android:id="@+id/toolbarLayout" android:background="@color/toolbar_bg">
    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="1" >
    </View>
    <ImageButton
        android:id="@+id/btnPanMode"
        android:layout_width="wrap_content"
        android:background="@null"
        android:onClick="onPanClick"
        android:layout_height="wrap_content"
        android:padding="3pt"
        android:src="@drawable/map_pan"/>
    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="1" >
    </View>
    <ImageButton
        android:id="@+id/btnSelectableLayers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="3pt"
        android:src="@drawable/layer_basemap_analyze32"
        android:onClick="onSelectableLayersClick"
        android:scaleType="fitXY"
        android:background="@null" />
    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="1" >
    </View>

</LinearLayout>

我想做的是验证上面xml中的第二个ImageButton是否显示.我的代码是:

What I'm trying to do is to verify the second ImageButton from xml above is displayed. My code is:

@SmallTest
public void testSelectableLayersIsOpen()
{
    onView((withId(R.id.btnSelectableLayers))).check(matches(isDisplayed()));
}

该代码仅工作一次.并且测试仅成功通过了一次.在我尝试第二次(并且多次)运行测试之后,我收到相同的错误:

The code has worked only one time. And the test was successfully passed only once. After I tried to run the test second time (and a lot of more times) I receive the same error:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: <package_name>:id/btnSelectableLayers
View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=658, height=802, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+->FrameLayout{id=-1, visibility=VISIBLE, width=616, height=760, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=21.0, y=21.0, child-count=2}
|
+-->FrameLayout{id=16908290, res-name=content, visibility=VISIBLE, width=616, height=760, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+--->LinearLayout{id=16908990, res-name=parentPanel, visibility=VISIBLE, width=616, height=760, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=4}
|
+---->LinearLayout{id=16908991, res-name=topPanel, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+----->LinearLayout{id=16908992, res-name=title_template, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+------>ImageView{id=16908294, res-name=icon, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+------>DialogTitle{id=16908993, res-name=alertTitle, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}
|
+---->FrameLayout{id=16908998, res-name=contentPanel, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+----->ScrollView{id=16908999, res-name=scrollView, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+------>LinearLayout{id=-1, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+------->TextView{id=16908299, res-name=message, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}
|
+------->Space{id=16909004, res-name=textSpacerNoButtons, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+---->FrameLayout{id=16909000, res-name=customPanel, visibility=VISIBLE, width=616, height=760, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+----->FrameLayout{id=16908331, res-name=custom, visibility=VISIBLE, width=616, height=760, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+------>RelativeLayout{id=-1, visibility=VISIBLE, width=616, height=760, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+------->ImageView{id=2131361875, res-name=imageView, visibility=VISIBLE, width=616, height=760, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+---->LinearLayout{id=16908995, res-name=buttonPanel, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=4}
|
+----->Button{id=16908315, res-name=button3, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}
|
+----->Space{id=-1, visibility=INVISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+----->Button{id=16908314, res-name=button2, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}
|
+----->Button{id=16908313, res-name=button1, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}
|
+-->ViewStub{id=16909171, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|

我不知道为什么会这样. 另外,如果我要在代码中添加新行-测试将再次通过,并且仅一次通过. 在我的情况下,我已经在上面的xml中添加了下一行:

I have no idea why it's happening. Also, if I'm adding a new line to the code - the test will passed again, and only one time again. In my case I've added next line to the xml above:

android:contentDescription="theMainMapViewFirst">

,我的测试通过了绿色测试.但是只有一次.在下一次运行中再次失败.

and my test has passed green. But only one time. It was failed again on just next run.

你们能帮我解决这类问题吗?

Could you guys please help me with such kind of issue?

推荐答案

类似,当espresso尝试查找视图时,您会在活动顶部显示一个对话框.

Looks like that you have a dialog displayed on top of the activity when espresso is trying to find a view.

看看espresso异常中输出的View Hierarchy转储,以了解它是什么对话框以及为什么显示它.

Take a look at the View Hierarchy dump that is outputted in the espresso exception to figure out what dialog it is and why it's showing up.

这篇关于意式浓缩咖啡测试仅在第一次通过.然后由于NoMatchingViewException而不断失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆