android - 如何检查一个元素是否在android espresso中另一个元素的右侧?
问题描述
我想使用浓缩咖啡检查一个元素是否在另一个元素的右侧。如何检查它。一个示例会有所帮助
ViewInteraction textView = onView(allOf(withId(R.id.name), withText("dín"), childAtPosition(childAtPosition(IsInstanceOf.<View>instanceOf(androidx.recyclerview.widget.RecyclerView.class), 0), 0), isDisplayed()));
文本 din 应该出现在左边的另一个文本的右边
解决方案
PositionAssertions帮助您测试屏幕上元素的相对位置(在 xy 平面上,z 平面被忽略)。
这是取自谷歌测试示例应用程序的示例文档
public void testRelativePositions() {
// left text should be left of right button although they share 1 pixel at the boundary.
onView(withId(R.id.left_text)).check(isLeftOf(withId(R.id.right_button)));
// Switch length button should be above Wrap button
onView(withId(R.id.length)).check(isAbove(withId(R.id.wrap)));
// Switch length button and Wrap button should be aligned to the left.
onView(withId(R.id.length)).check(isLeftAlignedWith(withId(R.id.wrap)));
}
推荐阅读
- sql - T-SQL:计算跨列和行的出现次数
- python - MDDropdownMenu 调用者上的 KivyMD KeyError
- java - 如何为 YAML 文件验证设计 maven-checkstyle-plugin?
- ansible - ANSIBLE 访问被拒绝/连接失败
- arrays - 程序未正确终止将二进制转换为十进制
- c# - 如何重定向到静态文件?
- ruby-on-rails - 图像未显示在基于 spree 的 rails 应用程序中
- python - 重叠两个一维网格并使用相对位置与 numpy 进行计算
- java - 如何避免在使用 getScaledInstance 时键入后获得 Null Pointer Deference?
- azure - 自 2020 年起通过 Azure Web App 对上传到 Azure 块存储的文件进行病毒扫描