Issue
I have spinner with custom layout:
<?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>
And I need to check if value in R.id.tv_text of selected item match with specific text.
Is it possible to do this without implement custom Matcher class ?
My simple test:
@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
}
}
Solution
I haven't found more simple way than create custom matcher that looks for specific text in any TextView (or their heirs) of Spinner selected item. There is a my custom matcher: https://gist.github.com/igorokr/5f3db37f0b9eb8b2feae
Answered By - IgorOK
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.