滚动屏幕到底部没有scrollview和没有ID,没有firstChild android-espresso自动化

Sta*_*ace 2 android-espresso

我想滚动到显示的当前屏幕的底部,但是

  1. 应用程序没有任何ScrollView.应用程序具有Horizo​​ntalScrollView但它不在上下文中.
  2. 在屏幕上使用带有ID的onView,TableLayout.但它会在层次结构中匹配多个视图时抛出错误.
  3. 使用onView,通过获取firstChild()但仍然会抛出错误而无法执行操作,使用类型parentMatcher的第一个子视图执行'滚动到'视图'时出错'.
  4. 试过onData(hasToString(startsWith().但是它会在层次结构中匹配多个视图时抛出错误.
  5. 试过其他方法,如获取当前的监视器和活动但仍然无法正常工作.

den*_*nys 6

好的,基于您问题中的少量信息,我可以提出建议:

  1. 简单的方法(但不完全正确) - 只需在GridView中向上滑动即可到达底部:

    onView(withId(R.id.GridView_Id)).perform(swipeUp());
    
    Run Code Online (Sandbox Code Playgroud)
  2. 简单方法:

    onData(instanceOf(Object_in_the_ROW.class))
        .inAdapterView(withId(R.id.GridView_Id))
        .atPosition(2)  //position # can very if you have header or not
        .check(matches(isDisplayed()))
        .perform(click());  //or any other action, or no action
    
    Run Code Online (Sandbox Code Playgroud)
  3. 方法我更喜欢:

    onData(withROWText("unique_text_in_ROW3"))
        .inAdapterView(withId(R.id.GridView_Id))
        .check(matches(isDisplayed()))
        .perform(click());
    
    Run Code Online (Sandbox Code Playgroud)

其中withRowText()是匹配ROW3中特定文本的自定义匹配器,类似于:

public static Matcher<Object> withRowText(String expectedText) {
    Checks.checkNotNull(expectedText);
    return withRowText(equalTo(expectedText));
}

public static Matcher<Object> withRowText(final Matcher<String> itemTextMatcher) {
    Checks.checkNotNull(itemTextMatcher);
    return new BoundedMatcher<Object, ROWObject>(ROWObject.class) {
        @Override
        public boolean matchesSafely(ROWObject rowObject) {
            return itemTextMatcher.matches(rowObject.text);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("with rowObject: ");
            itemTextMatcher.describeTo(description);
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

BTW,"GridView是一个以二维可滚动网格显示项目的ViewGroup ."