小编son*_*nic的帖子

使用 Espresso 检查视图是否被另一个同级视图隐藏

我想检查一个视图是否没有被另一个视图隐藏。我没有成功地使用经典isDisplayed断言来测试这一点。

就我而言,我在同一布局(FrameLayout)内有一个视图 A 和一个视图 B。我想测试视图 A 对用户是否可见。但我知道,这个测试应该失败,因为视图 ​​B 与视图 A 完全重叠。

布局示例:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <View android:id="@+id/view_a"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    />
    <View android:id="@+id/view_b"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    />
</FrameLayout/>
Run Code Online (Sandbox Code Playgroud)

测试代码:

onView(
    withId(R.id.view_a)
).check(
    matches(
        isDisplayed()
    )
)
Run Code Online (Sandbox Code Playgroud)

正如我之前所说,即使视图 B 完全位于视图 A 上方,此测试也不会失败。

如何使用 espresso 来测试我的视图 A 实际上对用户可见?例如,当使用translateX/Y任何其他方式移动或隐藏视图 B 时。

android android-espresso

5
推荐指数
1
解决办法
1502
查看次数

标签 统计

android ×1

android-espresso ×1