You need your test script to wait. My suggestion is one of the following:
- If the dialog always appears after exactly 30 seconds, use Thread.sleep(...)
- If the dialog appears after an inconsistent amount of time, use WebDriverWaits
WebDriverWaits are my favorite types of waiting used for automation. You only have to pass in an anonymous class whose only function is to check if the condition you're waiting on has appeared.
WebDriverWait dialogWait = new WebDriverWait(driver, 60); //60 for 60 seconds
dialogWait.until(new Predicate<WebDriver>() {
@Override
public boolean apply(WebDriver input) {
//Your check on the app's condition goes here
List<WebElement> myDialogButtons = input.findElements(By.className("android.widget.ImageButton"));
return myDialogButtons != null && myDialogButtons.size() > 0;
}
});
The way this works is that the WebDriverWait class's until() method runs your supplied apply() method in a loop until apply() returns true (or the timeout supplied in the WebDriverWait constructor is reached). Your apply() method should only return true when the state of your application is ready to continue with the rest of your test. If your apply() method returns false or throws a NoSuchElementException, then the WebDriverWait will wait 0.5 seconds before starting the next iteration in the loop.