我想使用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文本应该出现在左侧的另一个文本的右边
答案 0 :(得分:2)
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)));
}
答案 1 :(得分:1)
我能够将其与以下代码一起使用
ViewInteraction textView = onView(allOf(withId(R.id.name), withText("ble"), childAtPosition(childAtPosition(IsInstanceOf.<View>instanceOf(androidx.recyclerview.widget.RecyclerView.class), 0), 0), isDisplayed()));
textView.check(matches(withText("ble")));
textView.check(isCompletelyRightOf(withId(R.id.menu_level1)));