Espresso Test : app:compileDebugAndroidTestKotlin FAILED with Unresolved reference: PopupBackgroundView

201 views Asked by At

I recorded an EspressoTest in which I test values in spinner :

<LinearLayout
    android:id="@+id/linearLayoutSeedlingsTypes"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="40dp">
    <androidx.cardview.widget.CardView
        android:layout_width="180dp"
        android:layout_height="wrap_content"
        app:cardCornerRadius="20dp"
        android:innerRadius="0dp"
        android:shape="ring"
        android:thicknessRatio="1.9"
        android:backgroundTint="@color/green"
        android:background="@color/green">
        <Spinner
            android:id="@+id/fas_spinner_types"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginLeft="@dimen/default_margin"
            android:layout_marginStart="@dimen/default_margin"
            android:entries="@array/seedlings_types"
            android:spinnerMode="dropdown"
            />

It generated the following Kotlin class :

@LargeTest
@RunWith(AndroidJUnit4::class)
class AddNominalTest {

    @Rule
    @JvmField
    var mActivityTestRule = ActivityTestRule(MainActivity::class.java)

    @Test
    fun addNominal() {
            //...
            
            val materialTextView = onData(anything())
            .inAdapterView(
                childAtPosition(
                    withClassName(`is`("android.widget.PopupWindow$PopupBackgroundView")),//compile error !
                    0
                )
            )
            .atPosition(1)
        materialTextView.perform(click())
        
        //...
    

I have the following error at compile in app:compileDebugAndroidTestKotlin : Unresolved reference: PopupBackgroundView

Any idea about this error ?

1

There are 1 answers

0
drieu On

Jacek suggest me this solution:

val appCompatCheckedTextView2 = onData(anything())
    **.inRoot(isPlatformPopup())**
    .atPosition(0)
appCompatCheckedTextView2.perform(click())