如何在安卓浓缩咖啡中检查一个元素是否位于另一个元素的右侧



我想用浓缩咖啡检查一个元素是否在另一个元素的右侧。如何检查它。示例会有所帮助

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)));
  }

我能够让它使用以下代码

   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)));

最新更新