Appium Desired Capabilities — Basic Cheat Sheet to Launch Mobile Application (iOS / Android)

Ivan
Ivan
Oct 1, 2019 · 8 min read

Article is published and is updated as of 1st October 2019. This information may be outdated by the time you read it.(updated 18 October 2019)

Have you ever wonder what are the settings required you to launch your mobile application for iOS and Android using Appium ? Appium is the most popular framework currently to automate mobile application. To launch your mobile application before running your test scripts, you will need the right settings namely desired capabilities. This article deals specifically on this.

If you have managed to setup Appium on your machine, give yourself a pat on your shoulder. If you have not , please refer to this article link which I have written on step by step in setting Appium .

To launch a mobile application using Appium , we need to specify the right desired capabilities. This article is compiled from other articles [Reference 1, 2 & 3] and my experiences on what are the minimum desired capabilities to launch.

Desired Capabilities are keys and values encoded in a JSON object, sent by Appium clients to the server when a new automation session is requested. They tell the Appium drivers all kinds of important things about how you want your test to work. Each Appium client builds capabilities in a way specific to the client’s language, but at the end of the day, they are sent over to Appium as JSON objects. For more information on desired capabilities, refer to this link [Ref. 3].

The values could be found by asking the mobile developers in your team. Sometimes , we may not have access to the developers , so below are some of the hints how to get the values.

Android Desired Capabilities

Android (without APK)

Minimum settings to launch

  • deviceName
  • platformName
  • appPackage
  • appActivity

Example

"deviceName": "Nexus_9_API_28"
"platformName": "Android"
"appPackage":"my.app.helloworld"
"appActivity":"my.app.helloworld".common.activity.SplashScreen"

Android (with APK)

Minimum settings to launch

  • app
  • deviceName
  • platformName

Example

"deviceName": "Nexus_5X_API_26"
"app": "app":"//Users//username//myapp.app"
"platformName": "Android"

iOS Desired Capabilities

iOS (with app on simulator)

  • platformName
  • deviceName
  • app
  • automationName
  • platformVersion

Example

"platformName": "IOS"
"deviceName": "iPhone 6 Plus"
"app":"//Users//username//myapp.app"
"automationName": "XCuiTest"
"platformVersion": "12.4"

iOS (real device without app)

Minimum Settings to Launch

  • deviceName
  • bundleID
  • platformVersion
  • xcodeOrgId
  • platformName
  • automationName
  • app (if it is not installed)

Example

"deviceName": "iPhone-8"
"bundleId": "com.test.myapp"
"udid": "12314121211110111042111111"
"platformVersion": "12.1.4"
"xcodeOrgId": "123415151"
"xcodeSigningId": "iPhone Developer"
"platformName": "IOS"
"automationName": "XCuiTest"

Android — Finding appPackage and appActivity

[Ref. 1]

appPackage:

appPackage is the technical name of the app which is provided by its developers. It’s actually a top level package under which all the code for the app resides.

appActivity:

appActivity refers to the different functionalities that are provided by the app. It is where app is first launch and show the main activity

Method 1: Using ‘mCurrentFocus’ or ‘mFocusedApp’ in Command Prompt

You can run this command in command prompt, and it will provide the appPackage and appActivity name of the app which is currently in focus. Before you use this command, make sure that you complete the following pre-requisites –

Let us now start with the steps that you need to follow to find appPackage and appActivity name using the first method.

1. Unlock your mobile device and connect it to your computer using USB cable

2. Open Command Prompt and run ‘adb devices’ command. We are running this command to just make sure that your mobile is properly connected.

3. Once you run ‘adb devices’ command, you should see that it displays the list of attached devices as shown in the below image (the actual device name that you see would be different based on what mobile phone you use) –

4. Run ‘adb shell’ command. After running this command, the command prompt should look something like this –

5. Now in your mobile phone, open the app for which you want to find the appPackage and appActivity. Since we are doing this for Play Store, hence we will open “Play Store” on our mobile phone.

Note: Please make sure that you open the app before going to the next step, because command in the next step would provide the details only for the app which is currently in focus.

6. Now run this command: dumpsys window windows | grep -E ‘mCurrentFocus’

7. The above command would display the details of the app which is currently in focus. From that, you can figure out the appPackage and appActivity name as per the below image –

appPackage starts with com. and ends before backshash (/). So from the above image, appPackage name is — com.android.vending

appActivity starts after the backslash (/) and goes till the end. From the above image, appActivity name is — com.google.android.finsky.activities.MainActivity

8. There is one more similar command that provides the appPackage and appActivity name. This command adds some additional details before and after the package name & activity name, but you can still try it out just to verify that the results from the above command are same. This command is — dumpsys window windows | grep -E ‘mFocusedApp’ and the output of this command is shown below –

This completes our first method of identifying appPackage and appActivity name. However, there is one important point which you should keep in mind. For some apps, the appActivity name would shown as relative name in command prompt, i.e., it would not start with com. In such cases, you would need to add com…. at the beginning on your own.

For example, consider some app which shows com.myapp/.mainActivity in command prompt when you run the above commands. In this case, you will notice that the appActivity starts with a dot (which is a relative name). So you would need to add com… at the beginning. After adding the complete appActivity name that you will use would be — com.myapp.mainActivity

Method 2: Using APK Info app

APK Info is an app which you can download from Play Store, and it will provide the appPackage and appActivity name of any app which is installed on your mobile device.

Let us now start with the steps that you need to follow to find appPackage and appActivity name using the second method.

1. Download “APK Info” app from Google Play Store on your android mobile.

2. Once you have successfully installed APK Info app, open it and check that it lists down all the apps that you have on your phone. Then search for “Google Play Store” in the search pane as shown below

3. Long press on the “Google Play Store” application icon inside the APK Info app till it displays the list of options as shown below –

4. Click the option “Detailed Information” option. It would show the detailed log for the app.

Here, check the APK path section. This sections displays the “appPackage” name as highlighted in red block in the below image –

Note: Skip any number at the postfix of the name (eg: here its “-2”). So, the appPackage name in this case is — com.android.vending

5. Then to find the appActivity name of the app, scroll down to the sub-section “Activities”. This sub-section displays all the activities that are available for the app. From this list, you have to look for the activity which has “MainActivity” or “Main” or “Login” in the activity name.

Here “com.google.android.finsky.activities.MainActivity” is the appActivity name for the Play Store app.

Since Play Store is a full fledged app, so it contains a lot of activities. However, if you are testing a small app or some app which is in development phase, then it would not contain these many activities. So it would be easier to identify the main activity in that case. If you still find it difficult to identify the main activity, then you can always check back with your developers or use the first method that we have provided in this article.

Testing out if appActivity or appPackage is correct through adb

If these fails in Appium , run the following in command line in adb to confirm

adb shell am start -n com.package.name/com.package.name.ActivityName

If adb is able to launch, then you have got the appActivity and appPackage correct.

iOS Find BundleID

[Ref. 2]

Method 1: Find the bundle ID from the text file

Follow these steps:

  1. Open a desktop web browser, and then search for the app in the App Store in iTunes. For example, the URL of the Outlook app is https://itunes.apple.com/us/app/microsoft-outlook/id951937596?mt=8.
  2. Copy the number after id in the URL, which is 951937596 in the example.
  3. Open a new web browser window, and go to https://itunes.apple.com/lookup?id=<Number copied in step 2>. For example, https://itunes.apple.com/lookup?id=951937596.
  4. When you are prompted to download a text file, save the file. The default name of the file is 1.txt.
  5. Open the file, and then search for bundleId. Here is an example:
  6. “bundleId”:”com.microsoft.Office.Outlook”
  7. In this example, the bundle ID for the Outlook app is com.microsoft.Office.Outlook.

You can also review other important information in the text file, such as language code, supported devices, minimum OS version, and release information.

Method 2: Find the bundle ID from the .ipa file

To do this, follow these steps:

  1. Copy the .ipa file, and then change the file name extension to .zip. For example, rename Pages.ipa as Pages.zip.
  2. Expand the .zip file to a folder, and then search for the iTunesMetadata.plist file in the folder.
  3. Open the iTunesMetadata.plist file by using a text editor, and then search for softwareVersionBundleId. Here is an example:
  4. <key>softwareVersionBundleId</key>
  5. <string>com.apple.Pages</string>
  6. In this example, the bundle ID for the Pages app is com.apple.Pages.

Credits — Several of the above informations are extracted from the below references

References

  1. AutomationTestingHub — 2 Ways to find appPackage and appActivity name of your app . Link
  2. Microsoft — How to find bundleID for iOS. Link
  3. Appium — Desired Capabilities. Link
Ivan

Written by

Ivan

I am a Software Engineer. Follow me on Linkedin at linkedin.ivantay.org

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade