2014-09-25 91 views
0

我是使用UIautomator进行编程的新手,需要使用滚动设置从设置中选择一个选项“设备”。UiScrollable在UiAutomator中无法正常工作

这是我写的代码:

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

看起来这里有两件事情:

  1. 错误日志表明你已经改变了你的代码,但没有被重新编译它:)

    com.android.uiautomator.core.UiObjectNotFoundException: for text= "Voice"? - 根据您的代码,它应该已被取代为"Device"而不是

  2. 使用UiObject voiceButton = scroll.getChild(new UiSelector().className("android.widget.TextView").text("Device"));而不是UiObject voiceButton = scroll.getChildByText(LaunchClass.LAUNCHER_ITEM, "Device");

我真的不认为你需要sleep,如果你有clickAndWaitForNewWindow()

+0

对不起,我正在寻找这两种“声音”和“设备”两人都向下滚动。谢谢你会试试看! – 2014-09-29 04:42:44