agoda-com/Kakao

isDescendantOfA{ } and withMatcher(isDescendantOfA( )) not the same?

StanlyT opened this issue · 2 comments

Hey guys!
I have to get KTextView which is located in focused ancestor. I've written next method:

fun getFocusedKTextViewWithId(kTextViewId: Int) = KTextView{
    withId(kTextViewId)
    isDescendantOfA { this@TVScreen.getFocusedContainerWithClassName("FrameLayout")  }
}

and here i get such exception:

androidx.test.espresso.AmbiguousViewMatcherException: '(with id: id/text_view_time and is descendant of a: ())' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.

However next implementation works clear:

    fun getFocusedKTextViewWithId(kTextViewId: Int) = KTextView{
        withId(kTextViewId)
        withMatcher(isDescendantOfA(this@TVScreen.getFocusedContainerWithClassName("FrameLayout") ))
    }

Why is it happening?
Are there any differences between

   isDescendantOfA { method()  }

and

   withMatcher(isDescendantOfA( method() ) )

Hi there and thanks for reaching out!
isDescendantOfA {} in Kakao's ViewBuilder takes lambda with receiver of another ViewBuilder as argument, so inside of this lambda you need to match the descendant view with Kakao's functions.
You are free to use the actual ViewMatchers.isDescendantOfA() from Espresso through withMatcher() function of Kakao.

In your case when you call your function that returns Matcher<View> inside of Kakao's isDescendantOfA {} lambda it literally does nothing. If you have custom matcher it should look like that:

KTextView {
  isDescendantOfA { withMatcher(getMyMatcher()) }
}