1

image showing an input element with the text "vag@gmail.com", and an "x" in a circle on the right

The application has a custom email input field, how can I check that it displays the drawable icons in android test (espresso)

xml:

<com.my.mobile.kit.input.InputGeneral
        android:id="@+id/login_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginHorizontal="10dp"
        app:kitEndIconDrawable="@drawable/kit_ic_cleanitem_24"
        app:kitEndIconMode="clear_text"
        app:kitEndIconTint="@color/baseDeepGreyOne"
        app:kitLabelText="@string/m_auth_login_email_hint"
        app:kitLabelVisibilityMode="manual"
        app:kitPlaceholderText="@string/m_auth_login_email_hint"
        app:layout_constraintTop_toTopOf="parent" />
Zoe
  • 27,060
  • 21
  • 118
  • 148
Straider
  • 13
  • 2

2 Answers2

0

You can try using isDescendantOfA

    onView(
        allOf(
            withId(R.id.kitEndIconDrawable),
            isDescendantOfA(withId(R.id.login_email))
        )
   ).check(ViewAssertions.matches(/* check matches R.drawable.kit_ic_cleanitem_24 */))

Where kitEndIconDrawable is the id of the ImageView inside your custom view

Matching a drawable is a different topic, there are several approaches, you can use tags or some check the Bitmap, see these questions:

Using Espresso to test drawable changes

How to use espresso to test vector drawables

Mohamed Khaled
  • 139
  • 1
  • 7
0

This is a custom view then you should define custom ViewAction for perform click on that icon.

Something like this :

object OnCloseItemClick : ViewAction {
    override fun getConstraints(): org.hamcrest.Matcher<View>? {
        return ViewMatchers.isAssignableFrom(InputGeneral::class.java)
    }

    override fun getDescription(): String {
        return "whatever"
    }

    override fun perform(uiController: UiController?, view: View) {
        val customView: InputGeneral = view as InputGeneral
        customView.close_item_id.performClick()
    }
}

Now you can test this :

   onView(withId(R.id.login_email)).perform(OnCloseItemClick)
milad salimi
  • 1,580
  • 2
  • 12
  • 31