I want to acheive something like this.
Open Gmail app, look for a particular mail (scroll also) and click on it.
In the method below, I am able to search for a particular mail and click on it.
public void openMailWithParticularTitle(){
UiObject2 obj = Utils.getDeviceInstance().findObject(By.res("com.google.android.gm:id/recycler_list_view"));
List<UiObject2> mails = obj.findObjects(By.clazz("android.view.View"));
for(int i =0; i<mails.size();i++){
if(mails.get(i).getContentDescription()!=null && mails.get(i).getContentDescription().contains("My Mail Link")){
mails.get(i).click();
break;
}
}
}
But it only looks for visible items, doesn't scroll to look for child elements.
So I looked around and tried this, but this also doesn't seem to work due to some reasons.
public void scrollMailWithParticularTitle2() throws UiObjectNotFoundException {
openApp(Const.package_gmail_app,true);
UiScrollable settingsItem = new UiScrollable(new UiSelector()
.className("android.support.v7.widget.RecyclerView"));
UiObject about = settingsItem.getChildByText(new UiSelector()
.className("android.view.View"), "My Mail Link");
about.click();
}
Any help/ suggestion would be appreciated.
(I've limited knowledge of UI testing)
Try with scrollIntoView function:
Perform a scroll forward action to move through the scrollable layout element until a visible item that matches the selector is found
I used it once to find my app in apps menu:
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With