Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 313
Smriti Avatar asked Sep 17 '13 09:09

Smriti


2 Answers

UiDevice provides a few methods that may work for you:

public void waitForIdle(long timeout)

public void waitForIdle()

public boolean waitForWindowUpdate(String packageName, long timeout)
like image 123
Anders Avatar answered Sep 27 '22 20:09

Anders


I am no expert in UIautomator, but this can be done with Thread.sleep().

like image 29
Dnavir Avatar answered Sep 27 '22 21:09

Dnavir