Search code examples
javaandroidui-automationandroid-uiautomator

Providing delay between events in UiAutomator Android


How can I provide delay between event clicks in UiAutomator Android.

First event is entering a url in EditText :

new UiObject(new UiSelector().text("Search here")).setText("abc.com");
getUiDevice.waitForIdle(15000); 

Here I am loading a webpage inside a webview. So when url loading finishes , then I need to check for second event.

Second event is checking content description of a object :

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());
}

But this doesn't seem to be working.

I just want the app to wait for some time before checking for the second event.

I know these three methods are provided for delay in UI Automator -

public void waitForIdle(long timeout)

public void waitForIdle()

public boolean waitForWindowUpdate(String packageName, long timeout)

But I don't know how to use these methods.

Please suggest me a example how to use these.

Any help would be appreciated.

Thanks!


Solution

  • Try just

    sleep(5000);
    

    Let me know whether it works. Or you can try WaitForIdle( ) method.