Category Archives: Appium

                 This article will show you how to run first automation script for testing android mobile app using appium server.

Before that,  we need to create a new maven project and update the pom file with below mentioned Selenium dependency. I am assuming you are familiar with Java project creation in Eclipse. Let me include a brief step by step guide to creating a project.

  • Open Eclipse ( I’m using : Neon.1a Release (4.6.1) )
  • Click on File > new > Maven Project

  • Click on Next > Click on Next >

Where Artifact Id is your project name, Group Id is your project path folder structure

  • Click on Finish

Once the project is created, copy the below dependencies in the pom.xml file.

Just we created the maven project with updated pom.xml file and we need to launch some tools.

  1. UiAutomator viewer  —  Used to find out android mobile app elements (id, classname, XPath).
  2. Appium server  — inform the appium server which kind of session we are interested in (via Desiredcapabilities ).
  3. Real Device / Emulator.

UiAutomator viewer: Which is used to find out android mobile app elements like id. Classname, XPath.

If you want to open the UiAutomator viewer, Go through this path

Ex: C:\Users\akumar\AppData\Local\Android\sdk\tools

  • Connect your android device to PC via USB cable
  • Enable your device in “Debugging mode”.   
  • Click on uiautomatorviewer > Click on this image button to refresh the device screen in Automator viewer.

  • Make sure before click on above image button, we need to launch our android mobile with our app (Which we want to test the app).

Ex; Here I’ m using the  “ dialer “ android app for making a call to someone

  • After that, we need to click on image button which I have marked as red color.

  • clicking on the each node gives you properties of UI element in the lower panel

By the above Image will show you how to take android mobile app elements ( id, text, classname ).

    • text attribute can be used as “name”
  • a resource-id attribute can be used as “id”
    • class attribute can be used as “className”
  • a content-desc attribute can be used as “AccessibilityId”

If you want XPath, you can write manual XPath using below syntax

Locating Android App Element By XPath:

  1. XPath using class and text attribute:

Ex: Take Calculator android app:

Syntax:   //class_name[@Attribute=’Value’]

driver.findElement(By.xpath(“//android.widget.Button[@text=’5′]”))

IMP :-  I will show you one example about Dialer app testing, just copy the code and paste it inside your java class.

Then Start appium server, below steps, show you how to start appium server on command prompt

  1. Navigate to C: -> Program Files -> Appium -> node_modules folder.

 Ex: C:\Program Files (x86)\Appium\node_modules

  1. Press and hold Ctrl + Shift Keys of keyboard and press mouse right click.
  2. Select “Open command Window here” from the context menu.
  3. It will open a command prompt with navigation to given node_modules folder path.
  4. Type command ” node appium ” In command prompt and press enter then appium server will start.

Note: All set for running our script, make sure before running our script we need to launch first appium server.

Thank you for reading this article!

              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:

  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. A 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 appPackage name and appActivity name

Ex:

appPackage name: com.facebook

appActivity name : com.facebook.katana.LogoutActivity

Note: We have so many activities on a 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 “

  1. It will show you a list of apps(Which are installed in your device) with a package name.
  2. 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 “.

  1. Open app on the android phone. Immediately press CTRL + C in command prompt to stop logging in command prompt.
  2. Android phone’s latest activity will be logged in command prompt.
  3. If you see in the log, It will show you app launcher log.

If you want specific appActivity and appPackage on a 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 on command prompt

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 the .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!