[英]UiScrollable not working as expected in UiAutomator
我是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
如果有人能指出我在做什么錯,我將不勝感激,這是我第一次來,任何幫助將不勝感激。
看起來這里有兩件事:
錯誤日志顯示您已經更改了代碼,但是沒有再次編譯它:)
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");
。
如果您擁有clickAndWaitForNewWindow()
我真的不認為您需要sleep
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.