android - Espresso 检查 TextView 文本和 ImageView Drawable 是否在一起
问题描述
我有一个 ConstraintLayout,它是 GridView 内的一个列表项,因此屏幕上会有多个。每个项目都有各种状态,由drawables表示,每个列表项在drawable上方显示的TextView中都有一个唯一的名称。
基本上我在约束布局中有这两个:
<ImageView
android:id="@+id/client_state_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:src="@drawable/client_state_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/device_client"
style="@style/ClientName"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="72dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Whereclient_state_background
可以是多个可绘制对象之一,以编程方式确定。
我正在尝试运行浓缩咖啡测试,以确保正确的列表项显示状态的可绘制对象。我试过这样做:
ViewInteraction imageView = onView(allOf(withId(R.id.client_state_image), withParent(withParent(withId(R.id.grid_view))), withDrawable(statusToCheck), isDisplayed()));
imageView.check(matches(isDisplayed()));
但是我找不到在我的断言中包含 TextView 的方法。
有没有办法断言 TextView 和 ImageView 一起显示正确的信息?
解决方案
推荐阅读
- html - 如何使用 CSS 设置常规(未标记)HTML 文本的样式?
- c# - 在 Unity 中旋转对象时,脚本不会在 Z 轴上旋转对象,只有 X 和 Y?
- c# - 将返回值分配给变量时是否总是进行复制?
- python-3.x - 使用 Pyinstaller 的 SQLite3 和 python 的问题
- javascript - 将 props 传递给 Vue.js 中的另一个组件
- python - 使用 readlines 并以某种方式跳过两个 csv 文件中比较的第三列
- python - Django模型类__new__,传递给super().__new__的正确参数是什么?
- angular - 如何避免使用“禁用”属性来启用/禁用基于 FormGroup 的验证状态的 Angular 反应式表单控件?
- c# - 具有相同自定义模板/样式但不同绑定/上下文的多个 DataGrid 列
- c++ - 使用 Windows API 创建快捷方式 .lnk