문제

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);
도움이 되었습니까?

해결책

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 !!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top