Appium - Getting android app Package name and appActivity

While launching an application using Appium, it is required to have the appPackage and appActivity to set the Desired Capabilities. Earlier it used to be a long and tedious task to get these details from the apk file but now there are multiple easy ways to find this information.


Example:


capabilities.setCapability("appPackage", "com.whatsapp");
capabilities.setCapability("appActivity", "com.whatsapp.Main");


1. Using APK info android app
2. Using command prompt
3. Using logcat In Command Prompt
4. Using AndroidManifest.xml


Appium itself


The best and the easiest way to find the appPackage and appActvity is from the Appium itself. Before that you need to start your Appium client.

1) Start the Appium client. The Below mentioned window will display, Once you started the Appium client.


2) Click on the android icon marked above to open the configuration settings.
3) Check the Application Path check box.
4) Click on Choose button to locate your apk file, in this case, I have given it Flipkart.apk file.


Note: In case the correct information is not displayed in the Launch Activity field, click on the dropdown to look for the home.Home.Activity. Or if the information is not even there, try using the another way’s to find the information
Using APK info android app

Step 1: Just Download APK info app from AppStore
Once you downloaded the APK info app, Open the app


From there you will see android app’s which you are installed in your device, Just long press on the app which you want to get appPackage and appActivity.


Tap upon “Detailed Information”, there will see the appPackage name and appActivity name.


Ex:
appPackage name: com.facebook
appActivity name : com.facebook.katana.LogoutActivity

Note: We have so many activities on the mobile app, So make sure if you want to perform particular mobile interface(Screen) then choose that activity on APK info app.

Using command prompt

Get Package Name:
1. Connect your android phone to PC and turn on USB debugging mode.
2. Open Command prompt.
3. Run command " adb shell pm list packages -f "


4. It will show you a list of apps(Which are installed in your device) with the package name.
5. Find your app from the list. It will show you package name.

Using logcat In Command Prompt

1. Connect your android phone to PC and turn on USB debugging mode.
2. Open Command prompt.
3. Run command  “ adb logcat “.


4. Open app in the android phone. Immediately press CTRL + C in command prompt to stop logging in command prompt.
5. Android phone's latest activity will be logged in command prompt.
6. If you see in the log, It will show you app launcher log.


If you want specific appActivity and appPackage on particular mobile interface (mobile screen) :

On command prompt, type below commands

1. adb devices  -- it show’s how many devices connected to your pc/laptop
2. adb shell
3.  dumpsys window windows | grep -E 'mCurrentFocus|mFocusApp' .

Then you will get appPackage and appActivity. For example

C:\Users\akumar>adb shell
shell@otus_ds:/ $ dumpsys window windows | grep -E 'mCurrentFocus|mFocusApp'
 mCurrentFocus=Window{e5afac5 u0 com.android.mms/com.android.mms.ui.Conversatio
nList}
shell@otus_ds:/ $

appPackage : com.android.mms
appActivity : com.android.mms.ui.ConversationList

Using AndroidManifest.xml

1. Every .apk file contains AndroidManifest.xml file which contains android app's package and activity name

Steps:
1. .apk file for which you wants to get package and activity name.
2. WinRAR should be installed in your PC.
3. Right click on a .apk file of APK Info app(or any other .apk file for which you wants to know package and activity name).
4. Select Open with -> WinRAR archive option from right click context menu.



5. It will open the .apk file in WinRAR window and you can see AndroidManifest.xml there as shown in bellow image.




6. Open AndroidManifest.xml file in notepad
7. Now find keyword "p a c k a g e" In notepad. It will show you package name of your app.
8. Find keyword "a c t i v i t y" In notepad. It will show you activity name of your app.

I am sure the above different ways of finding APK information, one would definitely work successfully to you.


Thank you for reading this article!


Comments

Post a Comment

Popular posts from this blog

ReportPortal With Selenium, TestNG

Native Apps - Inspect elements by using UI Automator Viewer and Appium Desktop Inspector