What are capabilities?

Capabilities or DesiredCapabilities are simple key-value pairs encoded as JSON objects. These capabilities are sent by the client to the server, which could be a ChromeDriver service, GeckoDriver service, EdgeDriver service, or AppiumDriver service, to tell the server how the test should work and what features or capabilities to enable.

Every driver will have their own set of capabilities.

The following is a sample DesiredCapabilities JSON that the client requests from the Appium service for creating an AndroidDriver to test mobile web browsers.

{
  "browserName": "Chrome",
  "platformName": "Android",
  "deviceName": "Emulator",
  "udid": "emulator-5554",
  "automationName": "UIAutomator2"
}

We can search for the capabilities at https://caps.cloudgrey.io.

Capabilities for Android app automation

The following table shows the capabilities with respect to automating Android applications:

Capability Name Description Possible Values
automationName automation engine to use UiAutomator2
platformName mobile OS platform to use Android
platformVersion mobile OS version 7.1, 4.4, etc.
deviceName kind of mobile device or emulator to use Android Emulator, Galaxy S4, etc…
app absolute path of an .apk file or a .zip file that contains the .apk file or publicly hosted .zip file /path/.apk or /path/.zip or http://…/app.apk
otherApps app or list of apps (as a JSON array) to install at the start of running tests. It could be a local file or publicly hosted app [ “/path/.apk”, “http://…/app.apk” ]
autoLaunch initializes the app to test automatically. Defaults to true true or false
appActivity name of the activity to launch at the start of the session when autoLaunch is set to true. By default, it is inferred from the app if passed
appPackage Java package of the app under test. By default, it is inferred from the app if passed
udid unique device identifier of the connected physical device e.g. emulator-5554, 4sfdawg456
autoWebview move directly into WebView context. Default to false true or false
noReset do not reset app state before this session true or false
fullReset performs a complete reset true or false
chromedriverExecutable absolute local path to webdriver executable /abs/path/to/webdriver
unicodeKeyboard enable Unicode input. Defaults to false true or false
resetKeyboard resets keyboard to its original state after running Unicode tests with unicodeKeyboard capability. Default to false true or false
nativeWebScreenshot in a web context, use native (adb) method for taking a screenshot than proxying to ChromeDriver. Defaults – false true or false
autoGrantPermissions automatically determines which permissions your app requires and grants them to the app on install. Defaults to false true or false
networkSpeed sets the network speed emulation. Defaults to full “full”, “gsm”, “edge”, “hscsd”, “gprs”, “umts”, “hsdpa”, “lte”, “evdo”

There are more capabilities other than what is mentioned above. Follow these links – general-capabilities, android-only, uiautomator-capabilities - to learn more.

app is needed when fullReset is set to true. appPackage and appActivity are not needed if app is set. Either app or appActivity and appPackage are mandatory.

Finding app package & app activity

appPackage and appActivity are needed if we do not have the .apk file and launch and test an already existing app installed on the device. But they aren’t necessary if we have the .apk file as Appium will infer them.

We can find appPackage and appActivity in two ways:

  • Using aapt command
  • Manually by launching the app
Using aapt command

To use the aapt command, we need the .apk file.

If we want to fetch the .apk file of an already installed application on the device, run the following command and search for the app name that we want to test.

$ANDROID_HOME/platform-tools/adb shell pm list packages -f

Note: Replace $ANDROID_HOME with %ANDROID_HOME% if you are using a Windows machine.

For demonstration, let us find the appPackage and appActivity for the app Youtube.

The line that watches with the text “Youtube”, in the response of the above command, should look something like this:

package:/system/product/app/YouTube/YouTube.apk=com.google.android.youtube

For copying the installed app to our local machine using adb pull, run the following command:

$ANDROID_HOME/platform-tools/adb pull /system/product/app/YouTube/YouTube.apk youtube.apk

Now once we have the .apkfile, we can find the appPackage and appActivity using aapt.

aapt will be present at $ANDROID_HOME/build-tools/30.0.3/aapt, where 30.0.3 might change as per your local installation.

Run the following command and search for the texts launchable-activity and package to find the values of aapActivity and appPackage respectively.

aapt dump badging youtube.apk
Manually by launching the app

Incase launchable-activity is not showing up in the response of the above command, we can manually launch and monitor the app using the command adb log to see the activity that is launched when the application is starting.

We can look for the line that contains ActivityTaskManager and the package name we found using aapt command. It should look something like below:

I ActivityTaskManager: Displayed com.google.android.youtube/com.google.android.apps.youtube.app.WatchWhileActivity

From the above text, we find com.google.android.apps.youtube.app.WatchWhileActivity is the appActivity.

Get hands-on with 1200+ tech skills courses.