Android UI自动机/UI自动机2:滚动并在回收器视图中查找子UI元素

Android UI自动机/UI自动机2:滚动并在回收器视图中查找子UI元素,android,android-uiautomator,Android,Android Uiautomator,我想做这样的事。 打开Gmail应用程序,同时查找特定的邮件滚动条并单击它。 在下面的方法中,我可以搜索特定邮件并单击它 如有任何帮助/建议,将不胜感激。 我对UI测试知之甚少尝试使用功能: 执行前滚操作以在可滚动布局元素中移动,直到找到与选择器匹配的可见项 我曾经使用它在“应用程序”菜单中查找我的应用程序: UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); UiObjec

我想做这样的事。 打开Gmail应用程序,同时查找特定的邮件滚动条并单击它。 在下面的方法中,我可以搜索特定邮件并单击它

如有任何帮助/建议,将不胜感激。 我对UI测试知之甚少

尝试使用功能:

执行前滚操作以在可滚动布局元素中移动,直到找到与选择器匹配的可见项

我曾经使用它在“应用程序”菜单中查找我的应用程序:

UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiObject allAppsButton = mDevice.findObject(new UiSelector().description("Apps"));
allAppsButton.clickAndWaitForNewWindow();

UiScrollable appView = new UiScrollable(new UiSelector().scrollable(true));
appView.scrollIntoView(new UiSelector().text(APP_TITLE));
mDevice.findObject(new UiSelector().text(APP_TITLE)).clickAndWaitForNewWindow();
试用功能:

执行前滚操作以在可滚动布局元素中移动,直到找到与选择器匹配的可见项

我曾经使用它在“应用程序”菜单中查找我的应用程序:

UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiObject allAppsButton = mDevice.findObject(new UiSelector().description("Apps"));
allAppsButton.clickAndWaitForNewWindow();

UiScrollable appView = new UiScrollable(new UiSelector().scrollable(true));
appView.scrollIntoView(new UiSelector().text(APP_TITLE));
mDevice.findObject(new UiSelector().text(APP_TITLE)).clickAndWaitForNewWindow();

对于UIAutomator2;我已经创建了这两种方法,并且正在为我工作:

//This method returns child from scrollable parent using description


 public UiObject findChildFromScrollParentByDescription(String scrollParentClass, String childItemClass, String childDesc) throws UiObjectNotFoundException {
        UiScrollable parent = new UiScrollable(new UiSelector()
                .className(scrollParentClass));
        UiObject child = parent.getChildByDescription(new UiSelector()
                .className(childItemClass), childDesc, true);
        return child;
    }

//This method returns child from scrollable parent using text
public UiObject findChildFromScrollParentByText(String scrollParentClass, String childItemClass, String childDesc) throws UiObjectNotFoundException {
    UiScrollable parent = new UiScrollable(new UiSelector()
            .className(scrollParentClass));
    UiObject child = parent.getChildByText(new UiSelector()
            .className(childItemClass), childDesc, true);
    return child;
}

对于UIAutomator2;我已经创建了这两种方法,并且正在为我工作:

//This method returns child from scrollable parent using description


 public UiObject findChildFromScrollParentByDescription(String scrollParentClass, String childItemClass, String childDesc) throws UiObjectNotFoundException {
        UiScrollable parent = new UiScrollable(new UiSelector()
                .className(scrollParentClass));
        UiObject child = parent.getChildByDescription(new UiSelector()
                .className(childItemClass), childDesc, true);
        return child;
    }

//This method returns child from scrollable parent using text
public UiObject findChildFromScrollParentByText(String scrollParentClass, String childItemClass, String childDesc) throws UiObjectNotFoundException {
    UiScrollable parent = new UiScrollable(new UiSelector()
            .className(scrollParentClass));
    UiObject child = parent.getChildByText(new UiSelector()
            .className(childItemClass), childDesc, true);
    return child;
}

请看我的答案并建议哪个更好。请看我的答案并建议哪个更好。