How to "wait to activity" using Appium, on begin and during test itself? How to "wait to activity" using Appium, on begin and during test itself? android android

How to "wait to activity" using Appium, on begin and during test itself?


Specific activity means some specific element is being displayed.I use the following code to wait until some certain element on the screen:

WebDriverWait wait = new WebDriverWait(driver, 30);wait.until(ExpectedConditions.elementToBeClickable(By        .xpath("//android.widget.Button[contains(@text, 'Log In')]")));

or:

WebDriverWait wait = new WebDriverWait(driver, 30);wait.until(ExpectedConditions.presenceOfElementLocated(By            .xpath("//android.widget.TextView[contains(@resource-id, 'action_bar_title')]")));


You can use the following code to poll the current activity every second. If you want to reduce polling time you can reduce sleep time to 500 and wait*2 :

public void waitForActivity(String desiredActivity, int wait) throws InterruptedException{    int counter = 0;    do {        Thread.sleep(1000);        counter++;    } while(driver.currentActivity().contains(desiredActivity) && (counter<=wait));    log("Activity appeared :" + driver.currentActivity(), true);}


WebDriverWait wait = new WebDriverWait(driver,20);wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("about_me"))); 

If you wish to know in detail how implicit and explicit wait can be used in Appium then visit this TUTORIAL