我有一个使用选项卡布局的自定义视图页面(由于某些原因禁用了滑动)。内容根据选择的选项卡而变化。我想用浓缩咖啡测试一下:
1) 单击特定选项卡
2)查看选项卡特定页面的部分数据
我怎样才能做到这一点。我是浓缩咖啡新手
有几种方法可以做到这一点,一种简单的方法是通过选项卡标题选择元素,我使用以下代码:
Matcher<View> matcher = allOf(withText("TAB TITLE"),
isDescendantOfA(withId(R.id.customTab)));
onView(matcher).perform(click());
SystemClock.sleep(800); // Wait a little until the content is loaded
您只需调整匹配器以适应您的布局。
然后,检查内容。
例如:
onView(withId(R.id.someId)).check(matches(isCompletelyDisplayed()));
or:
onView(withText(R.string.someText)).check(matches(isCompletelyDisplayed()));
您可以在此处找到示例指定视图匹配器部分:http://developer.android.com/intl/es/training/testing/ui-testing/espresso-testing.html http://developer.android.com/intl/es/training/testing/ui-testing/espresso-testing.html
如果您使用 RecyclerView 来显示选项卡的内容,请看一下:ViewPager 内的 Espresso RecyclerView https://stackoverflow.com/questions/36945219/espresso-recyclerview-inside-viewpager/37157492
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)