在UiAutomator Android中提供事件之间的延迟

Smr*_*iti 9 java android ui-automation android-uiautomator

如何在UiAutomator Android中的事件点击之间提供延迟.

第一个事件是在EditText中输入一个URL:

new UiObject(new UiSelector().text("Search here")).setText("abc.com");
getUiDevice.waitForIdle(15000); 
Run Code Online (Sandbox Code Playgroud)

这里我在webview中加载一个网页.所以当url加载完成时,我需要检查第二个事件.

第二个事件是检查对象的内容描述:

UiObject curClass = new UiObject(new UiSelector().className("android.widget.RelativeLayout"));  
UiObject yCur = curClass.getChild(new UiSelector().description("ye"));
getCurCol();

public void getCurCol() throws UiObjectNotFoundException {
try {
    if (yCur.getContentDescription() != null)
        report.append("Success");
} catch (Exception e) {
    System.err.println("\nCaught Exception: " + e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)

但这似乎并没有起作用.

我只是希望应用程序在检查第二个事件之前等待一段时间.

我知道这三种方法是为UI Automator的延迟提供的 -

public void waitForIdle(long timeout)

public void waitForIdle()

public boolean waitForWindowUpdate(String packageName, long timeout)
Run Code Online (Sandbox Code Playgroud)

但我不知道如何使用这些方法.

请给我一个如何使用这些的例子.

任何帮助,将不胜感激.

谢谢!

int*_*thi 11

试试吧

sleep(5000);
Run Code Online (Sandbox Code Playgroud)

让我知道它是否有效.或者您可以尝试WaitForIdle()方法.


Dmi*_* Gr 6

如果您在按下按钮后需要等待

 UiObject settingsButton = mDevice.findObject(new UiSelector().text("Settings"));
        settingsButton.clickAndWaitForNewWindow();
Run Code Online (Sandbox Code Playgroud)

或者

settingsButton.waitUntilGone(1000);
Run Code Online (Sandbox Code Playgroud)

如果从意图启动新活动,这种方式是我能找到的等待设置包出现的最简单的方式:

mDevice.wait(Until.hasObject(By.pkg("com.android.settings").depth(0)), 2000);
UiObject settingsValidation = mDevice.findObject(new UiSelector().packageName("com.android.settings").text("Settings"));
        assertTrue("Unable to detect Settings", settingsValidation.waitForExists(4000));
Run Code Online (Sandbox Code Playgroud)