kyrax kyrax - 3 months ago 84
Android Question

Android Espresso - Click checkbox if not checked

I have

onView(withId(R.id.check_box)).perform(click())
, but i only want to do this if the check box is not already checked. How can I do this in espresso?

Answer

This seems to be part of your test, that the checkbox needs to be checked. You can check this by onView(withId(R.id.checkbox)).check(matches(not(isChecked()))); If this fails, your test will fail, which may be good in your case. Then, you can perform the click you want after this case matches. If this is not the situation you want, can you explain more on what you are trying to do in this Espresso Test?

Comments