如何从Espresso中获取视图以传递到IdlingResource? [英] How to get a view from within Espresso to pass into an IdlingResource?

查看:128
本文介绍了如何从Espresso中获取视图以传递到IdlingResource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上有一个自定义IdlingResource,它接受一个View构造函数参数。我找不到真正谈论如何实现它的任何地方。

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

我正在尝试使用这个答案: https://stackoverflow.com/a/32763454/1193321

I'm trying to use this answer: https://stackoverflow.com/a/32763454/1193321

正如您所看到的,它需要一个ViewPager ,但是当我在我的测试类中注册IdlingResource时,我不确定如何获得我的观点。

As you can see, it takes a ViewPager, but when I'm registering the IdlingResource in my test class, I'm not sure how I can get my view.

我尝试过findViewById()和我尝试获取当前正在运行的活动,然后调用findViewById(),没有运气。任何人都知道在这种情况下该怎么做?

I've tried findViewById() and I've tried getting the currently running activity and then calling findViewById() on that, with no luck. Anyone know what to do in this scenario?

推荐答案

想出来。要使视图传递到空闲资源,您只需要获取ActivityTestRule的成员变量

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

例如:

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

然后只需调用 getActivity()。findViewById(R.id.viewId )

所以最终结果是:

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

这篇关于如何从Espresso中获取视图以传递到IdlingResource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆