Android 10 was released in September 2019 and there is one important change that is very significant from an automation perspective. If the app you are testing has a target SDK version of less than 23 (Android 6.0), then when you launch it on Android 10, you might see a new permissions interstitial before your app launches those related to contacts, location, storage, SMS, microphone and camera. This blog aims to provide some help and thus, shares a few tips to avoid the permission interstitial during the automation in Android 10.
Prepare Appium Automation for Android 10
This is because of Android 10’s new, more app permissions model. Because these older apps haven’t been coded with an eye to the new permissions model, Android needs to pop up this annoying interstitial in order to make sure everything’s cool, permissions-wise. This is a slight annoyance for users, with a great gain in terms of privacy. However, it can be damaging for automation if your code isn’t expecting it. You have three options for what to do about this.
Option 1: Automate the Permissions View
The first option is the big hammer, you could just use Appium to automate this dialog by tapping the “Continue” button. But this means you have to throw a conditional in your test code for Android 10, and potentially waste a bunch of timing waiting for a “Continue” button that doesn’t exist on versions of Android less than 10. I used this kind of logic check but it wasted my automation execution time. So I don’t recommend it.
Option 2: Update your application’s targetSdkVersion
If you have access to your applications’ source code, or can convince your developers to do this, you could always update your applications’ targetSdkVersion to 29 (the SDK version of Android 10), and this will do away with the interstitial. Though of course, you’ll need to participate in the new permissions system, and that might require some code updates throughout the app.
Option 3: Use autoGrantPermission
The final option is most straightforward to use the autoGrantPermissions capability. If you include this capability and set it to true, Appium will attempt to automatically grant your app all permissions from the system perspective, so that when it comes tim`e to launch your app, Android already thinks that all permissions have been requested and accepted. You can set the capability as follows:
capabilities.setCapability(“autoGrantPermissions “, true);
Using this capability is nice because you might need it already (as a way to do away with dialogs popping up throughout the execution of your test), but also because you don’t need to update the app in order to use it.
Already Appium 1.15 supports Android 10, so make sure you download it whenever you need to automate apps on this Android platform. Don’t forget to use the last option. Following are the sample Desired Capability I used to Automation Android 10 devices,
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “One Plus”);
driver = new AndroidDriver<WebElement>(new URL(“http://0.0.0.0:4723/wd/hub”), capabilities);
This article helps the mobile automation engineers to achieve the automation on Android 10 without any new permission interstitial before launch of the applications. The autoGrantPermissions capability in Appium will gain more popularity for Android 10+ version. Make use of the new capability in your Android automation.
You might be interested to check out this article: Selenium C# – The Essential Test Automation Guide
Test Architect, RapidValue