【发布时间】:2017-02-27 09:11:40
【问题描述】:
我有这个测试大约有一半的时间。
@Test
public void thirdSwipe() {
onView(withId(R.id.pager)).perform(swipeLeft());
onView(withId(R.id.pager)).perform(swipeLeft());
onView(withId(R.id.pager)).perform(swipeLeft());
onView(allOf(withId(R.id.hint_english_text), withText("dog 0a"))).check(matches(isDisplayed()));
}
我遇到了这个失败:
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is displayed on the screen to the user' doesn't match the selected view.
Expected: is displayed on the screen to the user
Got: "TextView{id=2131427358, res-name=hint_english_text, visibility=VISIBLE, width=624, height=62, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=20.0, y=20.0, text=dog 0a, input-type=0, ime-target=false, has-links=false}"
所以,它看起来像是找到了 TextView 和 "dog 0a",但它无法识别它。
我查看了其他问题,并使用String 设置了文本,这只是我课堂上的几行:
private String englishText;
englishTextView.setText(englishText);
另外,我正在使用allOf()。
任何帮助,将不胜感激。此视图位于 ViewPager 的视图中,因此我不确定测试是否在 ViewPager idyl 之前发生,但它确实说它找到了视图。
【问题讨论】:
-
你关闭动画了吗?
-
是的,我关闭了动画。很抱歉没有提到这一点。
-
您更换设备了吗?对我来说,只有棒棒糖设备才能给出正确的结果。
-
@flobacca // 如何申请
waitId如此链接所建议的。它会持续检查,直到在给定时间内确认该值。 stackoverflow.com/questions/21417954/espresso-thread-sleep/…