2016-04-25 61 views
4

我有一个简单的线性布局,里面有两个文字浏览。线性布局具有唯一的ID,但textviews没有。我如何验证其中一个文本来自这些文字浏览?Espresso Android与父母内部的textviews匹配

我尝试下面的代码:

onView(allOf(NavigationDrawerComponent.topSectionWrapper, 
       hasSibling(withClassName(Matchers.equalTo(TextView.class.getSimpleName()))))) 
       .check(matches(withText(Data.fullUserName))); 

不幸的是,它的工作不适合我。我正在以下错误:

android.support.test.espresso.NoMatchingViewException: No views in 
    hierarchy found matching 

回答

4

使用hasDescendant()

onView(withId(R.id.recycler_view)).check(matches(atPosition(0, hasDescendant(withText("Available")))));