agoda-com / Kakao

This repo is no longer supported. Please visit a https://github.com/KakaoCup/Kakao
Apache License 2.0
1.11k stars 102 forks source link

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

Closed automaticqa closed 4 years ago

automaticqa commented 4 years ago

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() ) )
Unlimity commented 4 years ago

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.

Unlimity commented 4 years ago

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()) }
}