Created
September 4, 2019 06:52
-
-
Save rakib10rr3/522813ad0b7b635977253b64b43f7947 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This method selects any child from a viewgroup i.e: Chipgroup | |
private fun nthChildOf(parentMatcher: Matcher<View>, childPosition: Int): Matcher<View> { | |
return object : TypeSafeMatcher<View>() { | |
override fun describeTo(description: Description) { | |
description.appendText("position $childPosition of parent ") | |
parentMatcher.describeTo(description) | |
} | |
public override fun matchesSafely(view: View): Boolean { | |
if (view.parent !is ViewGroup) return false | |
val parent = view.parent as ViewGroup | |
return (parentMatcher.matches(parent) | |
&& parent.childCount > childPosition | |
&& parent.getChildAt(childPosition) == view) | |
} | |
} | |
} | |
//Call it like this | |
onView(nthChildOf(withId(R.id.cgPresent), 0)).perform(click()) // This will click on the first element of chipgroup | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment