我有带有自定义布局的微调器:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_icon"
android:layout_width="60dp"
android:layout_height="60dp" />
<TextView
android:id="@+id/tv_text"
android:textColor="#FFFFFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
我需要检查R.id.tv_text
所选项目的值是否与特定文本匹配。是否可以在不实现自定义Matcher类的情况下做到这一点?
我的简单测试:
@SmallTest
public class CategoryTest {
public static final String TEXT_TO_MATCH = "Spinner item text";
@Test
public void testCreate() {
...
onView(withId(R.id.spn_tt)).perform(click()); // open spinner
onView(allOf(withId(R.id.tv_text), withText(TEXT_TO_MATCH))).perform(click()); // find item by text and click
onView(withId(R.id.spn_tt)).check(matches(withTextInSpinnerSelectedView(TEXT_TO_MATCH))); // check if right item selected by text
}
}
除了创建自定义匹配器之外,没有找到比在Spinner选定项目的任何TextView(或其继承人)中查找特定文本的自定义匹配器更简单的方法。我有一个自定义匹配器:https : //gist.github.com/igorokr/5f3db37f0b9eb8b2feae
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句