Android Espresso - Click checkbox if not checked

前端 未结 5 998
长情又很酷
长情又很酷 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:27

    You have something like this in your code:

    @Rule
    public ActivityTestRule ActivityMainRule = new ActivityTestRule<>(ActivityMain.class);
    

    Try

    if (!ActivityMainRule.getActivity().findViewById(R.id.check_box).isChecked()) {
        onView(withId(R.id.check_box)).perform(click())    
    }
    

提交回复
热议问题