[英]Espresso: "Unresolved reference: atPosition"
我正在嘗試以我在 StackOverflow 上的各種答案中看到的方式使用 atPosition:
Espresso.onView(withId(R.id.rv_feeds))
.check(matches(atPosition(0, hasDescendant(withText("Test text")))));
Android Studio 找到除 atPosition 之外的所有需要的導入。 我是否可能缺少所需的 gradle 導入?
testImplementation "androidx.test.ext:junit-ktx:1.1.3"
testImplementation "androidx.test:core-ktx:1.4.0"
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation "androidx.test:core:1.4.0"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.4.0"
androidTestImplementation "androidx.test.ext:junit-ktx:1.1.3"
androidTestUtil 'androidx.test:orchestrator:1.4.0'
謝謝。
是的。 你錯過了:
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
似乎 atPosition 是某人編寫的一種擴展方法,不確定是否正確,但我在這個 stackoverflow 答案中找到了一個這樣的示例代碼並且運行良好: https ://stackoverflow.com/a/34795431/1241783
萬一鏈接斷開,這里是代碼片段:
public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) {
checkNotNull(itemMatcher);
return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
@Override
public void describeTo(Description description) {
description.appendText("has item at position " + position + ": ");
itemMatcher.describeTo(description);
}
@Override
protected boolean matchesSafely(final RecyclerView view) {
RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
if (viewHolder == null) {
// has no item on such position
return false;
}
return itemMatcher.matches(viewHolder.itemView);
}
}
};
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.