以下是我的AutoCompleteTextView下拉菜单的快照,我正从中选择第二项
我的Espresso代码:
onView(withId(R.id.searchContainer)).check(matches(isDisplayed()));
onData(anything())
.inAdapterView(withId(R.id.searchContainer))
.atPosition(1)
.perform(click());
但是我收到以下异常:
android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'with id: com.sampleaddressdd.demo:id/searchContainer'
使用Espresso Recorder,我得到以下代码:
DataInteraction appCompatTextView = onData(anything())
.inAdapterView(childAtPosition(
withClassName(is("android.widget.PopupWindow$PopupBackgroundView")),
0))
.atPosition(0);
appCompatTextView.perform(click());
下拉充气机代码:
mSearchView = findViewById(R.id.textSearch);
mSearchView.setDropDownAnchor(R.id.searchContainer);
mHttpClient.fetchAddresss(new HttpClient.AddressCallback() {
@Override
public void run() {
mAdapter = new AddressAdapter(MainActivity.this, mAddresss, new AddressAdapter.OnAddressClickCallback() {
@Override
public void execute(Address Address) {
startActivity(AddressProfileActivity.createIntent(MainActivity.this, Address));
}
});
runOnUiThread(new Runnable() {
@Override
public void run() {
mSearchView.setAdapter(mAdapter);
}
});
}
});
答案 0 :(得分:1)
最终通过使用
实现了这一目标onView(withText(LOCATION_TO_BE_SEARCHED)) .inRoot(withDecorView(not(mActivityTestRule.getActivity().getWindow().getDecorView()))) .check(matches(isDisplayed())) .perform(click());