我正在尝试使用Espresso
选择以下列表的第二项。
我的Android应用中有一个自动填充的文本,如下所示:
<AutoCompleteTextView
android:id="@+id/textSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_widget_margin"
android:background="@android:color/transparent"
android:inputType="textNoSuggestions"
android:hint="@string/text_hint_driver"
android:singleLine="true" />
它给了我下面的图片:
然后,当我键入“ Sa”时,我希望选择列表的第二个元素(按名称而不是按索引)。我认为,以下代码必须基于on this question对我这样做:
SystemClock.sleep(3000);
onData(equalTo("Sarah Scott"))
.inRoot(RootMatchers.isPlatformPopup()).perform(click());
我正在物理设备上运行,并且已关闭
但是,当我运行测试时,它抱怨以下错误:
androidx.test.espresso.PerformException: Error performing 'load adapter data' on view 'is assignable from class: class android.widget.AdapterView'.
at androidx.test.espresso.PerformException$Builder.build(PerformException.java:82)
.
.
.
Caused by: java.lang.RuntimeException: No data found matching: "Sarah Scott" contained values: <[Data: com.mytaxi.android_demo.models.Driver@b92ed3a (class: com.mytaxi.android_demo.models.Driver) token: 0, Data: com.mytaxi.android_demo.models.Driver@6b2ddeb (class: com.mytaxi.android_demo.models.Driver) token: 1, Data: com.mytaxi.android_demo.models.Driver@8884748 (class: com.mytaxi.android_demo.models.Driver) token: 2, Data: com.mytaxi.android_demo.models.Driver@16e79e1 (class: com.mytaxi.android_demo.models.Driver) token: 3]>
at androidx.test.espresso.action.AdapterDataLoaderAction.perform(AdapterDataLoaderAction.java:95)