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
?
This can be done using the startActivity command: driver. startActivity(new Activity("com. example", "ActivityName"));
Using Refresh command- driver. navigate(). refresh(); 2.
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')]")));
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
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);
}
long startTime = System.currentTimeMillis();
while(System.currentTimeMillis() - startTime < Time_Out)
if (getDriver().currentActivity().equals(activity))
break;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With