Appium Tip #9: How to Automatically Dismiss Dialogs and Autoaccept Alerts

Everything About Appium Test Automation

This is the 9th blog in our blog series 37 Things You Should Know About Appium.

One of those annoyances for mobile app testing using whatever test automation framework, real devices and/or real browsers, and different versions of Android and/or iOS platforms have been those automatic dialogs by operating system platform. When your test script is going through your app and doing its work to hammer those specific test details, a notification from OS might suddenly pop up. What to do and how to get rid of those and proceed the execution? We’ll cover that in this blog.


System Notification Problem with Test Automation and Testing

Notifications have been a discussed topic both among Android and iOS developers. Basically this feature that informs something about OS level – or just a push notification from certain app – can make test automation scripts work flaky sometimes. Naturally, there are workarounds and ways to get rid of that notification, but however we do not recommend using any blockers (or blocker apps) as those may have an impact on OS, execution and even performance of your test session. The easiest way to ‘get rid of’ these dialogs, notifications or popups is to generate an auto-accept click either by a run-time click or on an image recognized event. We’ll discuss about approaches here.

Desired Capability to AutoAccept Notification, Dialog and Popup

With Appium, and especially on iOS, automating those OS level popups is problematic. On iOS the permission alerts are system elements rather than something inside the automated app itself, which means you cannot create test steps to handle them. Those popups, notifications and dialogs may occur at random and must be handled instantly after test script sees those.

Appium has a simple solution to this. To solve this problem, you can use a desired capability specifically designed to handle these alerts.

You can either always accept or always dismiss the alerts with these desired capabilities:

autoAcceptAlerts = true
capabilities.SetCapability("autoAcceptAlerts", true);


autoDismissAlerts = true
capabilities.SetCapability("autoDismissAlerts", true);

Furthermore, some of the older versions of Appium haven’t worked with this solution, so you might want to try a small workaround with this:


Does Your Test Script Need Tweaks to Auto Accept/Dismiss?

To get these auto-accept/dismiss desired capabilities working with your test script and applications, you should definitely experiment which one works better (and faster) so that application or test script execution doesn’t slow down because of these auto-accept/dismiss capabilities.

On Android, pop-ups can be automated, since automation is not restricted only to one app at a time. The problem, though, might be how to identify the pop-up on screen. If a pop-up appears at the launch of your tested app, Appium inspector for example might not be able to bring out the element tree with the information. To solve this, you should use driver.getPageSource(). This command outputs the complete DOM, or Document Object Model, tree, which you can use to see all existing elements on the device. With this it should be simple to find any pop-up button elements and type them into your automated script as a test step.

Using Image Recognition to Get Rid of System Notification Popups

It’s quite common that these system notification dialogs pop up both on Android and iOS – for various reasons. One of the great workaround to get click done instantly on these notification dialogs is to trigger image recognition feature for the execution. When certain visual element or even part of visual element is shown on the screen, the script will trigger a click on “OK”. For example, with the standard Android notification it can be recognized from this visual notification:

Screen Shot 2015-11-09 at 12.23.07 PM

With iOS notifications there are typically two buttons to select activity for approving and getting rid of that notification. The image recognition example can work the same way and do the click for you (and for your actual test script). Typically on iOS there are two

Screen Shot 2015-11-09 at 1.26.39 PM

Screen Shot 2015-11-09 at 1.29.11 PM

If you are interested to learn how image recognition can help in these kinds of system notification popups, take a look at this blog.

We’ll be continuing next week with a new topic so stay hungry and keep testing your mobile apps!

Happy Appium Testing!

  • hari govind

    Thanks for the tip @Domestus111

  • Shabana Khanam

    hi there , Google services alert doesn’t get dismissed or auto accepted i’ve tried all three mentioned ways.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.