gpt4 book ai didi

android-viewpager - 如何使用tablayout在viewpager中设置当前选项卡

转载 作者:行者123 更新时间:2023-12-03 14:51:19 25 4
gpt4 key购买 nike

我有一个使用 tablayout 的自定义 viewpager(由于原因禁用了滑动)。内容根据选择的选项卡而变化。我想用浓缩咖啡测试这个:
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()));

或者:
onView(withText(R.string.someText)).check(matches(isCompletelyDisplayed()));

您可以在 中找到示例。指定 View 匹配器 部分: http://developer.android.com/intl/es/training/testing/ui-testing/espresso-testing.html

如果您使用 RecyclerView 来显示选项卡的内容,请查看以下内容:
Espresso RecyclerView inside ViewPager

关于android-viewpager - 如何使用tablayout在viewpager中设置当前选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33640635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com