Android Espresso : How to match grand parent? without giving exact hierarchy
<pre><code>onView(allOf(
        withText(activityUnderTest), 
        withParent(withId(R.id.llh_root_record_activity_3_item))))
    .check(matches(anything())) ;
</code></pre>

<p>In above code snippet <code>withParent</code> matcher is failing because view id given is not immediate parent but grand parent. </p>

<p>It can be handled as below, but curious to know the trick,specially when you don't want to specify messy  hierarchy as used in below code.  </p>

<pre><code>onView(allOf(
        withText(activityUnderTest), 
        withParent(withParent(withParent(withId(R.id.llh_root_record_activity_3_item))))))
    .check(matches(anything())) ;
</code></pre>