Android Espresso - Click checkbox if not checked

前端 未结 5 994
长情又很酷
长情又很酷 2021-02-18 13:58

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?

5条回答
  •  别跟我提以往
    2021-02-18 14:02

    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?

提交回复
热议问题