我试图找到一个 View 并尝试了不同的组合,但根据所有 stackoverflow 示例,我的逻辑看起来都是正确的。
我的代码:
onData(anything()).inAdapterView(
instanceOf(ListView::class.java))
.atPosition(0)
.onChildView(withId(android.R.id.title))
.check(matches(withText("Edit")))
.check(matches(isDisplayed()))
它会抛出错误:
E/TestRunner: androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (with id: android:id/title and is descendant of a: displaying data matching: ANYTHING within adapter view matching: an instance of android.widget.ListView)
If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:androidx.appcompat.widget.MenuPopupWindow$MenuDropDownListView{3df3337 VFED.VC.. ........ 0,0-539,264}
最佳答案
您可以根据您的情况尝试一下。不幸的是,我无法确定 onData() 在这里如何工作,但在研究之后你应该尝试这样的事情:
onView(withId(R.id.title))
.check(matches(withText("Edit")))
.check(matches(isDisplayed()));
关于java - Android espresso 在层次结构中找不到匹配的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60200742/