0

I'm trying to test if @drawable/ic_wifi ( this is the wifi symbol from the picture attached ) is displayed but the elem has no specific information

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        android:layout_weight="6.5"
        android:gravity="center">
    <FrameLayout
            android:layout_width="@dimen/home_with_internet_circle_size"
            android:layout_height="@dimen/home_with_internet_circle_size">

        <androidx.appcompat.widget.AppCompatImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:src="@drawable/bg_home_with_internet_circle" />

        <androidx.appcompat.widget.AppCompatImageView
            android:layout_width="wrap_content"
            android:layout_height="@dimen/home_connection_type_icon_size"
            android:layout_gravity="center"
            android:src="@drawable/ic_wifi" />

    </FrameLayout>

https://i.stack.imgur.com/SFYhO.jpg

Daniel
  • 39
  • 5

2 Answers2

0

If you want to test your drawable, then in Your application code you need to tag it first, like: setTag(R.drawable.your_drawable). You have it described in the topic below:

Using Espresso to test drawable changes

  • I don't want to be wrong but in that they use ids of elems, but I don't have any ids here – Daniel Sep 13 '19 at 11:37
  • If you wont add id to Your element, all You can do is search for elements of specified class, like `onView(allOf(instanceOf(ImageView::class.java))) .check(matches(isDisplayed()))` but it still won't help You with Your drawables – Michał Mosoń Sep 13 '19 at 12:18
0

If you can't add ID for your AppCompatImageView, you can find view by drawable. Example in Barista here (you can used Barista or create your custom matcher): https://github.com/AdevintaSpain/Barista/blob/967fa5a90a9c214cb23605f0b73bc4f18552f42c/library/src/main/java/com/schibsted/spain/barista/internal/matcher/DrawableMatcher.kt

For Barista use: Espresso.onView(button).check(ViewAssertions.matches(DrawableMatcher.withDrawable(R.drawable.ic_close_32px)));