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 onl
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')]")));
It can be done by different ways using element. Webdriver provide “WebDriverWait”, “ExpectedCondition” classes to implement this. ExpectedConditions class provide some set of predefine conditions to wait elements as:
Hope it helps...
I would suggest you to use WebDriverWait. Thread.sleep() is not a good way to use in your test scripts
long startTime = System.currentTimeMillis();
while(System.currentTimeMillis() - startTime < Time_Out)
if (getDriver().currentActivity().equals(activity))
break;
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