Frage

I'm new to android..How to use a wrapper function instead of sleep.

My scenario is: In my LG phone, After entering wireless password, until the wireless connection establishes I'm checking whether the connection is established or not using the text "Successfull".

For this I've used sleep for 40secs, post that I'm checking for the text. How to use wrapper function in this(it should continue to check for the text "Successfull" (say for a minute) then if text "Successful" is present it should continue or it should throw a error.

Existing code:

 UiObject wifi = new UiObject(new UiSelector().text("Successfull"));
 wifi.clickAndWaitForNewWindow();
 sleep(10000);
War es hilfreich?

Lösung

Instead of using sleep for 40 seconds and then checking you can use waitForExists API of UiObject.

UiObject wifi = new UiObject(new UiSelector().text("Successfull"));
boolean result = wifi.waitForExists(40000);//40 secs specified as timeout in ms
if(!result){ //View not found in 40 secs
   // throw error
}
wifi.clickAndWaitForNewWindow();

Hope this will help !!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top