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

Elad Benda2 picture Elad Benda2 · Mar 1, 2015 · Viewed 38.1k times · Source

I'm starting an already installed app using appium.

After my driver is initialized. How do I make it poll-wait till certain activity is displayed?

I saw only this way to wait for activity when starting up

cap.setCapability("app-wait-activity", "activity-to-wait-for");

Is there any other way? How do I wait to another specific activity when not initializing. Say after a button click?

just sleep x seconds ?

Answer

Alex picture Alex · Mar 2, 2015

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')]")));