Skip to content

Instantly share code, notes, and snippets.

@rakib10rr3
Created September 4, 2019 06:56
Show Gist options
  • Save rakib10rr3/d544eb0494a6009d900d2d28389ec00c to your computer and use it in GitHub Desktop.
Save rakib10rr3/d544eb0494a6009d900d2d28389ec00c to your computer and use it in GitHub Desktop.
//This method will work on a checkbox. It will set the state of checkbox either checked or unchecked
private fun setChecked(checked: Boolean): ViewAction {
return object : ViewAction {
override fun getDescription(): String? {
return null
}
override fun getConstraints(): Matcher<View> {
return object : BaseMatcher<View>() {
override fun matches(item: Any): Boolean {
return isA(Checkable::class.java).matches(item)
}
override fun describeMismatch(item: Any, mismatchDescription: Description) {}
override fun describeTo(description: Description) {}
}
}
override
fun perform(uiController: UiController, view: View) {
val checkableView = view as Checkable
checkableView.isChecked = checked
}
}
}
//Call it like this
onView(withId(R.id.addressCheckbox)).perform(setChecked(false)) //It will uncheck the box
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment