浓咖啡:通过指定父视图避免AmbiguousViewMatcherException

问题描述

onView(withId(R.id.Feeding_name)).check(matches(isdisplayed()));导致AmbiguousViewMatcherException。

由于屏幕上有多个片段,因此ID“ Feeding_name”与多个视图匹配。

我想知道,是否有任何方法可以指定视图的父级,以便我可以做类似onView(withIdAndParentId(R.id.Feeding_name,R.id.fragment_show_Feeding)).check(matches(isdisplayed()));的事情

解决方法

您可以尝试将匹配器与allOf结合使用,例如:

onView(allOf(withId(R.id.feeding_name),withParent(withId(R.id.fragment_show_feeding))))
    .check(matches(isDisplayed()));