我的测试应用程序位于显示的第二页,当使用appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()),"<appName>",true)
时,它找不到应用程序。 (如果应用程序位于第一页本身,我的代码可以正常工作)
下面提到我的代码:
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());
}
日志附在下方:
"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)"
所以我的问题是:
1。不滚动并找到应用程序
2。如果我使用appViews.setAsHorizontalList();
,我会收到"INSTRUMENTATION_STATUS: stack=java.lang.NoSuchMethodError: com.android.uiautomator.core.UiScrollable.setAsHorizontalList"
错误..
请帮忙。
答案 0 :(得分:3)
我会发布解决方案,一切正常,而且更简单:)
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();
这将通过您拥有的所有屏幕搜索想要的应用程序,直到找到它为止。只需使用您的应用名称编辑UiObject navigationDrawerApp = new UiObject (new UiSelector().text("Contacts"));
并运行代码
答案 1 :(得分:0)
我找到了一份文件here。但是当我跟进时,我在编译时遇到了这个错误。
[javac] CalculatorTest.java:20: error: cannot find symbol
[javac] UiObject seven = new UiObject(new UiSelector().resourceId("com.android.calculator2:id/digit_7"));
[javac] ^
[javac] symbol: method resourceId(String)
[javac] location: class UiSelector
[javac] CalculatorTest.java:24: error: cannot find symbol
[javac] UiObject plus = new UiObject(new UiSelector().resourceId("com.android.calculator2:id/op_add"));
[javac] ^
[javac] symbol: method resourceId(String)
[javac] location: class UiSelector
[javac] CalculatorTest.java:27: error: cannot find symbol
[javac] UiObject one = new UiObject(new UiSelector().resourceId("com.android.calculator2:id/digit_6"));
[javac] ^
[javac] symbol: method resourceId(String)
[javac] location: class UiSelector
[javac] CalculatorTest.java:30: error: cannot find symbol
[javac] UiObject result = new UiObject(new UiSelector().resourceId("com.android.calculator2:id/eq"));
[javac] ^
[javac] symbol: method resourceId(String)
[javac] location: class UiSelector
[javac] 4 errors
在project.properties
文件中将内部版本号更改为18+。
# Project target.
target=android-23
编译器不使用eclipse项目中使用的lib,但在使用此命令生成build.xml
时,请根据目标编号使用lib:
android create uitest-project -n MyFirstTest -t 23 -p
上面的代码将创建一个project.properties
文件,其中包含目标号码。如果数字太低(如5),则lib中没有此方法,则会发生错误。
您可以使用此命令显示目标ID:
android list target
希望这有效!