Android Espresso与文本不匹配,即使它就在那里 - "swipeRight"和"swipeLeft"的问题



更新:所以我省略了这个视图在ViewPager内。事实证明,我的问题是"向左滑动"和"向右滑动"的解释。我错过了这么长时间的原因是因为我会手动运行这些步骤,而我认为的"向右滑动"与 Espresso 认为的向右滑动不匹配。所以我没有看到问题发生,直到我在我的代码周围投入了一堆睡眠,这样我才能看到它以慢动作进行。那时我意识到它走错了方向。所以真的,整个问题就是因为这个。哎呀。不知道如何处理这个问题,因为我在技术上可以自己回答,但它与帖子的内容相去甚远,因为我省略了 ViewPager 位。

源语言:

我正在对文本进行非常简单的检查,但它不想通过。

onView(withText("My text")).check(matches(isDisplayed()));

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError:"显示在屏幕上给用户"与所选视图不匹配。

预期:在屏幕上向用户显示

得到: "CustomTextView{id=2131756070, res-name=label_name, visibility=VISIBLE, width=506, height=53, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-request=false, is-selected=false, root-is-layout-request=false, has-input-connection=false, x=220.0, y=375.0, text=My text, input-type=0, ime-target=false, has-links=false}">

这是布局代码:

<snip.snip.CustomTextView
android:id="@+id/label_name"
style="@style/typographyH4Subheading"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="@{viewModel.nameLabel}"
android:ellipsize="end"
android:singleLine="true"/>

知道什么可能导致这不匹配吗?

视图在disaplay上真的可见吗?例如,如果它不在视口中并且您需要滚动isDisplayed()则会失败。 另一个问题可能是给定视图的某些父视图具有不可见或消失的可见性。

您可以尝试.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));涵盖第一种情况,并从此示例中isVisible涵盖第二种情况。

您是否只有一个给定文本的视图?

看到了您的更新,但如果您仍然想swipe,您应该尝试ViewPagerActions.scrollRight()它看起来与swipeRight()非常相似,但这是我能够让我的viewpager正确滑动的原因

相关内容

最新更新