我是UIautomator编程的新手,需要选择一个选项" Device"来自使用滚动的设置。
这是我写的代码:
public class LaunchClass extends UiAutomatorTestCase {
public static final UiSelector LAUNCHER_ITEM = new UiSelector().className(android.widget.TextView.class.getName());
public void testDemo() throws UiObjectNotFoundException {
//new UiObject(new UiSelector().text("Email")).clickAndWaitForNewWindow();
getUiDevice().pressHome();
UiObject settingsClick = new UiObject(new UiSelector().description("Settings. App. Item *23 of *24 on page *1."));
settingsClick.clickAndWaitForNewWindow();
UiScrollable scroll = new UiScrollable(new UiSelector().scrollable(true));
scroll.setAsVerticalList();
sleep(5000);
UiObject voiceButton = scroll.getChildByText(LaunchClass.LAUNCHER_ITEM, "Device");
sleep(5000);
voiceButton.clickAndWaitForNewWindow();
执行此操作时,它会向下滚动,但不会选择"设备",我认为滚动速度可能比点击速度慢,因此引入了睡眠 - 但这并不好。
这是我得到的错误:
testDemo中的错误:
com.android.uiautomator.core.UiObjectNotFoundException: for text= "Voice"
at com.android.uiautomator.core.UiCollection.getChildByText(UiCollection.java:125)
at com.android.uiautomator.core.UiScrollable.getChildByText(UiScrollable.java:201)
at com.android.uiautomator.core.UiScrollable.getChildByText(UiScrollable.java:181)
at com.uia.example.my.Sairam.testDemo(Sairam.java:23)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:144)
at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:87)
at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:90)
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:235)
at dalvik.system.NativeStart.main(Native Method)
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stack=com.android.uiautomator.core.UiObjectNotFoundException: for text= "Voice"
at com.android.uiautomator.core.UiCollection.getChildByText(UiCollection.java:125)
at com.android.uiautomator.core.UiScrollable.getChildByText(UiScrollable.java:201)
at com.android.uiautomator.core.UiScrollable.getChildByText(UiScrollable.java:181)
at com.uia.example.my.Sairam.testDemo(Sairam.java:23)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:144)
at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:87)
at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:90)
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:235)
at dalvik.system.NativeStart.main(Native Method)
INSTRUMENTATION_STATUS: test=testDemo
INSTRUMENTATION_STATUS_CODE: -1
INSTRUMENTATION_STATUS: stream=
Test results for WatcherResultPrinter=.E
Time: 10.974
FAILURES!!!
Tests run: 1, Failures: 0, Errors: 1
如果有人能够指出我做错了什么,我将不胜感激,这是我的第一次,非常感谢任何帮助。
答案 0 :(得分:0)
看起来这里有两件事:
错误日志显示您已更改了代码,但尚未对其进行再次编译:)
com.android.uiautomator.core.UiObjectNotFoundException: for text= "Voice"
? - 根据您的代码,它应该为"Device"
而不是
使用UiObject voiceButton = scroll.getChild(new UiSelector().className("android.widget.TextView").text("Device"));
代替UiObject voiceButton = scroll.getChildByText(LaunchClass.LAUNCHER_ITEM, "Device");
。
如果您有sleep
clickAndWaitForNewWindow()