My test app is in the second page of display and when use appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()),"<appName>",true)
it is not finding the app. (My code works fine if the app is in the first page itself)
Below mentioned my code:
public void testFindAndRunND() throws UiObjectNotFoundException {
getUiDevice().pressHome();
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
appsTab.click();
UiScrollable appViews =new UiScrollable(new UiSelector().className("android.view.View")
.scrollable(true));
//appViews.setAsHorizontalList();
try{
UiObject navigationDrawerApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), "QA FCU", true);
navigationDrawerApp.clickAndWaitForNewWindow(3000);
}
catch(Exception e) {
appViews.swipeRight(1);
System.out.println("Not Exists^&********");
}
UiObject navigationDrawerValidation = new UiObject(new UiSelector().packageName("com.ifs.mobilebanking.fiid9901"));
System.out.println("Verify the App is launched!!!!!!!");
assertTrue("Unable to find the Application", navigationDrawerValidation.exists());
}
Log is attaching below:
"INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: test=testFindAndRunND
INSTRUMENTATION_STATUS: class=`com.android.uiautomator.tests.demoTests`
INSTRUMENTATION_STATUS: current=2
INSTRUMENTATION_STATUS_CODE: 1
Not Exists^&********
Verify the App is launched!!!!!!!
INSTRUMENTATION_STATUS: numtests=3
INSTRUMENTATION_STATUS: stream=
Failure in testFindAndRunND:
junit.framework.AssertionFailedError: Unable to find the Application
at com.android.uiautomator.tests.demoTests.testFindAndRunND(demoTests.java:105)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:160)
at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:96)
at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:91)
at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:248)
at dalvik.system.NativeStart.main(Native Method)
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: test=testFindAndRunND
INSTRUMENTATION_STATUS: class=com.android.uiautomator.tests.demoTests
INSTRUMENTATION_STATUS: stack=junit.framework.AssertionFailedError: Unable to find the Application
at com.android.uiautomator.tests.demoTests.testFindAndRunND(demoTests.java:105)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:160)
at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:96)
at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:91)
at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:248)
at dalvik.system.NativeStart.main(Native Method)"
So my issues are:
1. Not scrolling and finding the app
2. If I use appViews.setAsHorizontalList();
, i get "INSTRUMENTATION_STATUS: stack=java.lang.NoSuchMethodError: com.android.uiautomator.core.UiScrollable.setAsHorizontalList"
Error..
Please help.
Here is the solution, everything works, much simpler too:
getUiDevice().pressHome();
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
allAppsButton.clickAndWaitForNewWindow();
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
appsTab.click();
UiObject appViews =new UiObject(new UiSelector().resourceId("com.sec.android.app.launcher:id/apps_grid"));
UiObject navigationDrawerApp = new UiObject (new UiSelector().text("Contacts"));
while (!navigationDrawerApp.exists()){
appViews.swipeLeft(3);
}
navigationDrawerApp.clickAndWaitForNewWindow();
This will search for the wanted app trough all the screens you have until it finds it. Just edit the UiObject navigationDrawerApp = new UiObject (new UiSelector().text("Contacts"));
with your app name and run the code