How to get a view from within Espresso to pass into an IdlingResource?

后端 未结 4 1984
无人及你
无人及你 2021-01-03 20:59

I essentially have a custom IdlingResource that takes a View a constructor argument. I can\'t find anywhere that really talks about how to implemen

4条回答
  •  醉梦人生
    2021-01-03 21:20

    Figured it out. To get the view to pass into an idling resource, all you have to do is take the member variable of your ActivityTestRule

    For example:

    @Rule
    public ActivityTestRule activityTestRule = new ActivityTestRule<>(
            MainActivity.class);
    

    and then just call getActivity().findViewById(R.id.viewId)

    So the end result is:

    activityTestRule.getActivity().findViewById(R.id.viewId);
    

提交回复
热议问题