Handling popups in native app

I am using Appium to automate a native iOS and Android app using Java.
The app features a Login/Logout proccess, which I execute in the start/end of every test case, and while logged in the app, apart from all the actions that I can do there, there are many random pop-ups for “Rate us” system, enabling Notifications, Locations usage and many more.
The problem is that some of those pop-ups are coded to appear in different intervals of time, so what I am doing now is waiting to dismiss them in the start of each and every case after Login (This takes a lot of time for all the pop-ups to appear).

Is there a way to wait throughout the whole case for the popup(s) to appear and then be dismissed, while executing the other steps, or is the only workaround to dismiss all the popups before executing the rest of the case?

How about try adding to your Desired Capabilities (“autoAcceptAlerts”,true);

1 Like

Thanks sunny,

I think this will work only for iOS…

Also this would be only for system alerts, I am having popups from the native app, for which I am using locators to map and close, like XPath or name, for example “Close” button.

So what I need is something to “Listen” throughout the whole case for the certain element to appear and than interact with it, for closing the desired popup, dialog or else, without interrupting the flow. Does Appium support such a feature?

Hi @Arokh

Can you please elaborate your question …

Hi, @Vallabhaneni_Rakesh,

So basically my whole question is if I can interact with certain button elements from the app, but only in the time of their appearing, as they can appear at any random time and break the flow of the case (because if your are searching for a button and the pop-up appears, the only thing left to do is dismiss/accept the popup).

For example, I Login the app, dismiss one popup, with driver.findElement(By.name(“Close”)).click(); , and then continue with the rest of my case. But the same popup could or could not appear in the second case, after a random amount of time.

My question is what can I use to check if that popup appears throughout the case, if it appears at all and close it with driver.findElement(By.name(“Close”)).click(); while my script runs, and not wait specifically to close the popup for lets say 10 minutes and only then continue with the script execution.

// wait for alert to popup
// switch to alert
// dismiss alert using any locator strategy

hope this helps

Yes, this will dismiss the alert, but you need this code to be run exactly when the alert is going to popup, at the best, you need a wait of 10 secs, before each and every element interaction in the script, to make sure that all the random alerts that pop-up are going to be handled - this appears to be slow and time-consuming for the script.

For now, I found the best solution to be to add an If (Else if) Else statement, which checks for the alerts before every step.

Looks like this in Java:

	List<?> !button = !driver.findElements(By.id("!buttonID"));

It’s important to add the elements to a List like so, and to use !driver.FindElements instead of !driver.FindElement, so execptions are not thrown.

1 Like

And for android ??
please guide

thanks in advanced. It’s exremely useful to me

I’m facing difficulty with modal open for the subscription. How can I automate modal?
Should I use frame or something else?