Where we learn technology

Day: 1 May 2020

Appium Tutorials

5. Recorder in Appium Inspector

Recorder in Appium Inspector

Recorder option is one of an advanced feature in Appium Inspector, Recorder is used to record an action that is performed on the Inspector window.

Fine, I can understand recorder option is used to record a keystroke. Fact is most of the other tools are also having such features what is great in Appium?

Yes, we have some great features in Appium recorder. It will not only record your actions, also it converts the actions performed to your preferred programming language SYNTAX. For example, if you click on any button it will give you a syntax like below,

MobileElement el1 = (MobileElement) driver.findElementById(“allow_button”);


Powerful right? Please find a sample screenshots below to understand better.

How to use Recorder option in Appium Inspector?

I have connected to my app under test and I’m currently in Inspector window,

 I have a popup in my mobile screen. I have to either to accept or Deny.

Now, I’m taking a “Start Recording” option so that all my actions will be recorded.

Once you clicked the “Start recording” button, the button image changes from eye to pause button like this,

It states, your actions are now listening by Recorder. I’m now going to click on “Allow” button on popup using Inspector (Not on your mobile phone)

As I clicked the “Allow” button you can now see all list of attributes for the button displayed on the right hand side view

There I’m taking “Tap” option so that the event will be happen in real device and actions will be recorded in the Recorder.

After clicking “Tap” button, you can see the page gets refreshed in the Inspector window and also the recorder is having a small piece of code for the action performed.

Based on the available Location strategy the find element syntax will be generated automatically.

Like this you can add many actions like performing a swipe action, sendkeys on any text box etc…

Supported programming Languages on Recorder

Now, the recorder code is showing as “Java-Junit” program. As Appium supports other programming languages also it should allow the user to see the recorder steps in other languages also right?. Yes this feature is available. Based on your preferred language you can select the same in Appium.

Using the dropdown displaying in the screen for programming language, you can select your preferred language.

Currently Appium can provide the recorder codes using the below langagues,

  • Java Script (JS)
  • JS for WebDriver.io
  • Java- Junit (our regular core java code)
  • Python
  • Ruby
  • Robot Framwork.

I just selected Python as my preferred language and see the code is now displaying in Python.

Using JavaScript for Webdriver.io

What is “Boilerplate” in Appium recorder?

Now comes to the secret section, there is another impressive feature in hidden in Appium that is called, Boilerplate code under Recorder screen. Boilerplate will give you half cooked code on your preferred language.  Once all your actions recordings are over or still in progress, you can use Boilerplate option to see how the code looks like in your SDK.

Boilerplate Icon:

Now see the magic, I have selected to show the code using Boilerplate and Appium gave me some piece of code with Junit annotations. See the fantasy this is what we need to put in our Base class in our framework. (image is cropped and showed here for clear understanding)

See how powerful it is. In just given time Appium created a test case for us with Junit annotations.

You can simply copy paste this in a regular java file in eclipse/NetBeans and execute as a Junit test.

Not only in Java, see the Python code below,

With the help of Recorder option, we can not only record our actions also we can generate codebase for our actions on your preferred language.



Naveen AutomationLabs

Blog Contributors:

Author:  Ragavendran

Ragav, having 10+ years of testing experience on which 7 years of rich experience in automation using UFT, Selenium (Java/Python). Expertise in Web and Mobile automation testing using Appium.


Reviewer: Naveen Khunteta 


4. Appium “Locator strategies”

So far we have seen how to connect our real device/Emulators using Appium. In this session we will focus on how to inspect an object/Element using Appium Inspector.

As I already mentioned in one of my previous blog that, the most important and powerful feature in Appium is Inspector. Because it will help us to find an element and its attributes in simple manner. The Inspector screen is simple and lightweight. One can easily inspect an element and the hierarchy model displayed for the screen will be quite interesting.

Salient features of Inspector:

  1. The hierarchy view of elements
  2. Just a click on preferred element to inspect
  3. You can easily find the element and swipe coordinates
  4. For instant recognition of element, we can use inbuilt buttons like “Tap” and “SendKeys” to click on any particular element and to pass value to any input field. 
  5. Allows to save and modify the Desired Capabilities for future use
  6. On every successful element inspection, attributes like “Name”, “Value”, “Label”, “ID”, “XPath” etc… will be displayed separately in a tabular column
  7. Based on platform, there are lot of location strategy available to find an element like “ID”, “Xpath”, “Class Name”, “UIAutomator Selector”, “Class Chain”, “NSPredicate” etc…

There are list of locator strategy available in Appium based on platforms. Based on its priority level, easy approachability and performance we can select the appropriate locator strategy 

Locator strategies Supported Platform
accessibility id or ID Android and iOS
Name Android and iOS
class Name Android and iOS
Uiautomator selector Android
Predicate string iOS
Class chain iOS
Xpath Android and iOS

Remember: Few Selenium based Locator Strategies like “css selector”, Linktext, tagname, partiallinktext are not supported by Appium API’s because mobile page source (DOM) is not XML based.


One of the simplest and most commonly used location strategy. In fact every element has an own ID associated with it.

In Android, we can use attributes as ‘ID’ or ‘resource-id’

In XCUI, we can use name or label. [Preferred only for static field values]


This locator is commonly used for iOS based application. In android this locator is recognized as an attribute “content-desc”.  This is one of the best strategy to use for both Android and iOS because it will be same in both the platforms if the app is designed using ReactNative or Xamarin. 

Android: accessibilityid or “content-desc” is always a preferred choice due to its performance.

XCUI: accessibilityid should be used carefully, because for dynamic fields, id will change as per value of the field. So preferred only for static fields.


driver.findElementByAccessibilityId(String selector);

driver.findElement(MobileBy.AccessibilityId(String selector));

driver.findElementById(String selector);

driver.findElement(MobileBy.id(String selector));

@iOSXCUITFindBy(accessibility = “selector”)

@AndroidFindBy(accessibility = “selector”)


This is one of a common locator strategy in Appium or selenium. Element will be identified using the name of the field.


            driver.findElement(MobileBy.name(String selector));

            driver.findElementByName(String selector);


As we already seen, the “Appsource” hierarchy in Inspector tags are nothing but a className.

For IOS it is the full name of the XCUI element and begins with XCUIElementType.

For Android it is the full name of the UIAutomator2 class and begins with android.widget.

Example: XCUIElementTypeButton and android.widget.Button


driver.findElement(MobileBy.className(String selector));

driver.findElementByClassName(String selector);

@iOSXCUITFindBy(className  = “selector”)

@AndroidFindBy(className = “selector”)

UIautomator selector:

UIAutomator API is an Android native way of finding element, it uses UISelector class to locate elements. In Appium you send the Java code, as a string, to the server, which executes it in the application’s environment, returning the element or elements.


driver.findElement(MobileBy.AndroidUIAutomator(“new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\””+ find_text + “\”).instance(0))”));

Appium allows user to use some list of attributes with UiSelector(). Few listed below,




We can use UIautomator strategy with UiScrollable function for some complex operations like, auto scrolling and finding an element with the given conditions.

Predicate string:

This locator strategy is in my favorite list when it comes to XCUI automation. This is a NativeJS search approach powered by Apple for its own SDK (XCode) and you can design it more like an XPath query.

There are lot of logical and comparative operators are available for Predicate sting. Please go throw the site



@iOSXCUITFindBy(iOSNsPredicate = “type == ‘XCUIElementTypeStaticText’ AND name BEGINSWITH[c] ‘Shipping Address:'”)



Class chain

One of a best and powerful locator strategy designed to replace Xpath and for quick digging and finding the hierarchical elements. This is designed by Appium team. This locator strategy is in my favorite list when it comes to XCUI automation.


@iOSXCUITFindBy(iOSClassChain = “**/XCUIElementTypeTable[2]/XCUIElementTypeStaticText[1]”)




We all know XPath very well, a commonly used and powerful strategy especially for dynamic elements, no need to explain much as we all much use to it.

Web testing without XPath is unimaginable. Also xpath is considered to be the unreliable location strategy.

Appium allows user to use XPath for certain conditions but it is not recommended due to its performance also for some other good reasons like.

  • Due to dynamic changing of elements in mobile, path hierarchy will not be same all the time
  • XPath will take lot of time to find an element (depends on number of elements in the page)
  • Mobile native is not having its DOM as XML. You can find that in Appium Inspector
  • Leads to StaleElementException in many cases

In Android you can see some moderate performance using XPath, but in XCUI it is highly not recommended instead we can go for Predicate String or Class Chain strategy.

How to find an Element by navigating via AppSource?

Now let’s enter into the practical way of Inspecting Elements. Please follow the below steps,

Step 1: To inspect an element we need to know how to enter Desired Capabilities and how to launch the Appium session. If not then please refer to my previous blogs for details.

All set and connection is established successfully, once the mobile phone screen got captured on Appium Inspector you can start spying the elements.

For this tutorial I have selected “JetAudio” media player application for XCUI. You can select any of your preferred application. Come let’s see how to inspecting Elements for XCUI.

My Desired Capabilities are

I have selected “Start Session” and my connectivity established successfully.  So that you can see my mobile phone screen on Inspector.

Take a look on how the “App Source” is getting displayed here. There are two entries in the name of “XCUIElementTypeWindow”. The 1st entry is the entire application frame and the second entry is for the footer section (the advertisement that is displaying in the footer). You can expand the 1st row to find out all the parent and child elements of the selected screen.

See the expanded view of App source, the splendor here is all the displaying in the App Sources are nothing but a Class name of an element/frame. Impressive right?

You can also see that, all element attributes are getting displayed in the right side view of Inspector for the selected element. This is why I have mentioned it is one a powerful feature of Appium.

Okay all fine. I can see all the attributes of the element… But my question is How to inspect an element? How can I do that?

Yes, let me clarify. Once you can see the app view in Inspector, All you need to do is just a click on the chosen element from the screenshot. For example in the below screen shot, I can see the home page of jetaudio player and I have simply clicked on the Hamburger menu (blue highlighted).

On click of the element, Appium will automatically detects and display’s all the attributes of the element including xpath. It will also display the hierarchical view in “App Source” like below.

Now we have all the attributes in hand, with the help of these attributes we can easily write location strategies in our code. For example the screen shows the “accessibility id” as “navi menu” so that I can write my location identification strategy using “ID”.

driver.find_element_by_id(‘navi menu’) or driver.findElementById(“navi menu”);

How to inspect an element using locator and Selector?

Okay now we will see how to find an element using locator? Finding an element using locator made simple in Appium. Clicking on the icon “Search for elements” will give you list of locators applicable to use with selenium.

locator strategy can be an ‘ID’ or ‘xpath’ or ‘Name’ and we have to enter the Selector value as per the locator selected.

Select the needed locator strategy and enter the Selector (value) in the screen and click on “Search”.

I have selected “ID” as a locator and entered the Selector as “navi menu”

On click of “Search” button the next screen will appear if the given selector is valid and found in the screen. Inspector will always shows the elementID as a search result.

On click of the elementID the searched element will get highlighted in the background screen so that we can recognize and confirm whether the highlighted element is what we are looking for.

We can use the same way for inspecting elements using other locator strategy like UIAutomator, xpath, classchain or Predicate.

One should know how to frame a UIAutomator selector, Predicate string queries. So that it will become easier to inspect element using Inspector.

Just showcasing how to find element using Predicate/ Class chain in the below screens,

For example, if you want to select a complete list of elements belongs to a single class name, then you can query without giving any selection criteria like

  • **/XCUIElementTypeButton   -> class chain
  • Type == “XCUIElementTypeButton”    -> PredicateString

So that this class chain query will fetch complete List of elements having the class name “XCUIElementTypeButton” and returns a List

This query returns a list of 17 MobileElements. And clicking on each elementID’s from search result will highlight the corresponding element in the background.

We will see how to capture these list of MobileElements using Java List and how to iterate/assert the values in upcoming sessions.

Hope it is clear now on how to inspect an element using Appium Inspector.



Naveen AutomationLabs

Blog Contributors:

Author:  Ragavendran

Ragav, having 10+ years of testing experience on which 7 years of rich experience in automation using UFT, Selenium (Java/Python). Expertise in Web and Mobile automation testing using Appium.


Reviewer: Naveen Khunteta 


2. Appium on Macintosh(Mac)

In this chapter we will find out the prerequisites for connecting iOS real device/ Simulator with Appium 

Prerequisites for Appium on Mac:

  • To automate iOS for mobile or iPAD OS for tablets, it is must to have a Mac machine.
  • XCode should be installed properly to get the SDK files for connectivity
  • XCode should be kept upto date to get the latest iOS/iPAD OS support
  • You must have a valid Apple developer ID for provisioning profile
  • NODEjs must be installed in the device

What is WDA ?

WDA stands for WebDriverAgent. As the name says this is the bridge/agent for Appium to send or receive Proxy commands to a real device/ simulators.

WDA was developed by Facebook for their hybrid app testing. Later it was acquired by Appium and now it is managed by Appium team. Still the WDA’s bundle ID is “com.facebook.bundleID” with few facebook libraries imported. WDA is designed using Objective C you can see the code by opening the WDA framework in XCode.

Don’t get confuse with XCode and XPath. Usually happens for me while talking J just kidding…

It is a good practice to change the WDA bundleID from “com.facebook” to some generic name like “com.UIAutomation” or something. Else if you are using any client provided enterprise Apple DEV ID for compilation, then you can see facebook.com all over bundleID’s which may create IT auditing issues. Don’t worry changing BundleID cannot stop you from compiling or building the WDA codebase.

How to download WDA ?

  1. WDA comes with Appium desktop, so no need to download separately
  2. You can find WDA as a framework and not as an app.
  3. It is our responsibility to compile the WDA framework and installing it in the device for test
  4. Once installed make sure you have given trust access for the WDA from “Device and Management” option from General settings screen. Else it will be considered as an untrustworthy app and it will become inaccessible from Appium. (Only for Real devices)

Where to find the WDA framework in Mac machine?

  1. Go to Finder and Applications,
  2. Search the Appium application and take right click on Appium icon
  3. Take “Show Package Contents” option from right click menu
  4. Navigate to the path “Contents/Resources/app/node_modules/appium-webdriveragent/”
  5. Open the file “WebDriverAgent.xcodeproj” in Xcode.

How to compile the WebDriverAgent.xcodeproj in XCode ?

Open the file WebDriverAgent.xcodeproj in XCode, so that you can see the WDA program in XCode like below,

Make sure you have selected the proper device from the “Devices” list

Make sure you are using your AppleID on build settings under “Provisioning Profile” on xcode version <=10 and “Signing & Capabilities” on xcode version >=11. Now, go to “Product” click on “Build”

I have selected the option “iPad Pro (12.9 inch)(3rd Generation) simulator, it means I’m going to install WDA on simulator now

If you face any compilation issues you can find that in the left hand side menu like this

You can ignore the warnings but not error’s (please refer the topic “Common WDA compilation issues” below if you face any error) and now Once Build is successfully compiled, go to “Product” and take option “Test”. This option will start the Simulator and install WDA as an App

Now the selected simulator will be opened and the app will start installing on the simulator

WDA installed successfully on the Simulator

Limitation in using Appium on MAC Machine?

As we all know Appium is a platform independent tool. We can run Appium on Windows/ Mac/ Linux. But yes there are few limitations when it comes to device platform.

  1. Using Appium, you can automate Android phones using any Windows/ Mac machine(Android SDK is must).
  2. You cannot automate iOS application using Appium from Windows/Linux based machines.

Why Automating iOS devices are not possible with a Windows machine?

There are lot of reasons we can list out, few most common reasons are

  • Windows by default will not have support for advanced iOS operations. You can perform only basic file data transfer option but installation of any app or debugging options are not available from Windows.
  • XCode which is a commonly used SDK for iOS app. XCode support is not available for windows-based OS. 
  • Without XCode you cannot install WDA (WebDriver Agent) to iOS devices, so from windows it is impossible.

Commonly facing WDA installation/ compilation issues:

  1. Provisioning Profile:

If you are using your personal Apple development ID for more than 2 devices then you will definitely face provisioning profile issues while compiling. The solution is either you need to untag few devices from your apple dev account or you need to change the apple ID in your app build settings. FYI… Provisioning profile is applicable only for real devices

  • ‘RoutingHTTPServer/RoutingConnection.h’ file not found

For the first time if you are building WDA then you have to face this issue for sure. This is happening because of missing “bootstrap” script configuration. To overcome this issue, open Terminal and open the path where WDA project file exist, (“/Applications/Appium.app/Contents/Resources/app/node_modules/appium-webdriveragent/”) and type the command “./Scripts/bootstrap.sh -d”. This command will help you to resolve the h file not found issue.

  • CocoaAsyncSocket.h not found

Again a common and must face issue while compiling WDA, This needs no action to be taken. Just close the XCode and open the WDA project again.

This issue may come if you have installed Appium CLI. Because the CarthageKit that installed as a part of Appium CLI may cause issue. If restarting XCode didn’t solve the issue then uninsall/remove CarthageKit from terminal using the below command

rm -rf ~/Library/Caches/org.carthage.CarthageKit

One more major issue/concern in WDA is, auto clean-up while initiating the Appium connectivity. We will discuss about this topic in upcoming sessions.

Blog Contributors:

Author:  Ragavendran

Ragav, having 10+ years of testing experience on which 7 years of rich experience in automation using UFT, Selenium (Java/Python). Expertise in Web and Mobile automation testing using Appium.


Reviewer: Naveen Khunteta 


3. How to connect to a mobile device using Appium?

How to connect to a mobile device using Appium?

Appium requires few parameters (or) Capabilities to connect to an Emulator. Capabilities are nothing but an attributes or properties of the mobile device under test. In normal if any one asks about your phone, we use say about the phone make and model, which Android OS version it is running and in addition about some apps those are installed in the device.

Appium also requires the same details to be entered. It demands for the basic Capabilities to initiate the connection,

Capabilities Description
platformName Can be Android or iOS depends on the mobile device platform under test
platformVersion OS version, for example if Android it can be ‘8’ or ‘9.1’ for iOS 12 or 12.2 like that. Can be seen in android settings -> about phone
DeviceName” or “UDID Name of the device under test, can be get using “ADB devices” command. UDID is for iOS  (Unique Device Identifier)
appActivity” and “appPackage Have to provide Package name and Activity name of the application under test.
bundleID BundleID is the identification of App on iOS.


How to get the PlatformVersion from the device?

Take the device under test, goto settings and select option “About Phone” and make a note of “Android Version”

What is an “appActivity” and “appPackage”?

appActivity and appPackage are one of the basic technical identification of the android application. When the developers are developing the application they have a set “Application/Library Name”, here Package name will be derived from the Module Name. Please refer the screen below

Activity is a main module for an android app. It is nothing but a “screen name”. If any android app got opened, the very first screen what we are seeing is an Activity. For example, if I open WhatsApp application the first screen that load with a WhatsApp logo is an activity screen usually said as “Splash Activity” then it will navigate me to list of chats that’s another activity. Likewise whatever screen we are seeing in the app are called Activity. In android app development setting up an activity is the initial step. Whenever an app is launched it means some activity is in progress.

Below listed are few predefined Activities from Android studio. Just for your understanding

Developers can use the existing activity as it is or modify them or create a new one.

Here you can see how to name an Activity, In Appium we will use the “appActivity” name given here.

Now, we know what is “appActivity” and “appPackage” and how developers are creating that. It’s time to fetch these details after an app was created. Once the code is extracted as an apk file we cannot modify the app using android studio to fetch these details because converting to app means encrypting the code and make it as executable. (Same like jar file, have you ever used .jar or .class file to view the source code? it will be in encrypted format right, same like that).

So in that case how to fetch these values? There are certain steps and debugging commands given in Android studio, with the help of those we can easily find the “appActivity” and “appPackage”. Please find the steps below,

How to “appActivity” and “appPackage” for the app under test?

Step 1: Connect the device using USB cable

Step 2: Make sure in android “Developer Options”, “USB Debugging” and “Install via USB” options are enabled.

Step 3: Verify ADB DEVICES command is showing the connected device name

Step 4: Open command prompt and type the command ADB SHELL and enter.

Step 5: Start the app manually in mobile device

Step 6: While the app is starting up execute the below command in command prompt dumpsys window windows | grep -E ‘mCurrentFocus’

Step 7: The above command will list out the app package and activity. Make sure you have taken the exact start up activity(screen name) else it will endup with failure while executing/connecting. I mean the activity of the startup page should be taken.

Step 8: Package name should be like “com.testapp.main” and activity should be like “com.testapp.ui.activity.MainActivity”

If you follow the above steps you will get an output like this in command prompt (console/terminal)

If you don’t find any attached devices after executing adb devices command, then make sure whether the device is connected properly along with

  • Developer options should be enabled. Usually you will get dev access by clicking the “Android version” row 6 times continuously from settings screen. If not then check in google on how to enable the developer access with your device make and model. Because each OEM’s are having their own style of giving dev access.
  • USB Debugging” option must be enabled in device to enter in debugging mode.

All good so far. Also we have all the capabilities ready so it’s time to connect our device to Appium.

How to add “Desired Capabilities” in Appium?

Opened my Appium Desktop, here I’m just trying to connect and launch the app under test using Appium so selected the Simple mode. As we already seen Appium will start with its default Host “” and Port “4723’, I’m simply clicking on “Start Server” button

We have started our Appium server successfully and the server is listening on

Ok, then how to connect to our device ?

Connecting to our device made very easy by setting up the “Desired Capabilities”. For that click on the LENS icon called “Start Inspector Session” on the top of Appium server

You will be landed to Appium “Desired Capabilities” page where you can add your device and app capabilities  

Select “Automatic Server” as default and you can see the below sections,

  • It’s mentioned, on which host & port server is currently listening to
  • Advanced Settings
  • Desired Capabilities section
  • JSON Represenation

We are now going to work in Desired Capabilities section, take ‘+’ icon labled button and create around 5 rows and start filling the capabilities like below,

Appium capabilitites are case sensitive so please make sure you are giving capabilities correctly.

Capabilities Description
platformName Android  
platformVersion 9
deviceName Output from “adb devices” command
appActivity Activity we got using the “adb Shell” command
appPackage Package we got using the “adb Shell” command

You can see whatever Capabilities we entered are convered into JSON format. This is because appium will consume its DesiredCapabilites always in JSON format, in other words “Key” & “Value” pair like Hashmap in java.

Don’t forgot to save the capabilities using “Save As” button else it will endup with data loss.

All set, now its time to start our connectivity, for that just click on “Start Session” to initiate the connectivity.

Verify whether your device is getting any popup like below screens, If yes “Accept or Install” all popup. This is because appium is trying to install the app called “Appium Settings” to your device.

“Appium Settings” app is a bridge for Appium to communicate with the device (Same like “WDA“ for iOS what we seen in our previous blogs). Once the app is installed your App under test should be opened and displayed in Inspector screen like below.

We connected the device successfully and good to go with Inspecting the Elements.

You can also refer Appium logs to findout the proxy commands, request and responses

Commonly facing connectivity issues:

  1. An unknown server-side error occurred while processing the command. Original error: Cannot read property ‘toLowerCase’ of undefined”
    1. If any Capabilities are set incorrectly can be a spelling mistake or Case sensitivity issue. Verify all capabilities very thoroughly
  2. “An unknown server-side error occurred while processing the command. Original error: Unable to find an active device or emulator with OS 8. The following are available: ****** (9)”
    • This error will come if deviceVersion capability is incorrect
  3. An unknown server-side error occurred while processing the command. Original error: Cannot start the ‘com.invoiceapp’ application. Original error: Cannot start the ‘com.invoiceapp’ application. Original error: Activity name ‘.com.invoiceapp.InvoiceLaunchScreenAct’ used to start the app doesn’t exist or cannot be launched! Make sure it exists and is a launchable activity
    • If appPackage or appActivity is incorrect
  4. If you do not get any popup for “Appium Settings” installation (or) if connection not established with Appium, then verify “Install via USB” option is enabled in android general settings under “Developer Options”. This usually gets enabled by default. If not make sure it’s enabled.

  • Miscellaneous Errors
    • Make sure you can see the device listed in “ADB Devices” list
    • Make sure “Appium Settings” app is installed on the device
    • Make sure your device is not locked (i.e. you should see some active screen)
    • Make sure App under test is installed on the device.


Naveen AutomationLabs

Blog Contributors:

Author:  Ragavendran

Ragav, having 10+ years of testing experience on which 7 years of rich experience in automation using UFT, Selenium (Java/Python). Expertise in Web and Mobile automation testing using Appium.


Reviewer: Naveen Khunteta 


6. Connect to Appium using Java / Python

So far, we have seen how to connect the mobile device in Appium Desktop.

Now it’s time to see how we can connect the device and start testing the app using Java. Hence Java is our preferred language for this training, I will try to include code snippets for Python as well.

How to connect to Appium using Java code?

As we all know Appium will connect to any mobile device with the help of DesiredCapability. In this session we are going to discuss about how internally our Java code is communicating with Appium with the help of Appium libraries.

 Have you ever worked in Selenium grid? If yes, then it will be very easy for you guys to understand the Appium design. For example, in Selenium Grid we will use DesiredCapability to help Selenium grid library to identify the nodes right? Appium also uses the same methodology. Appium server acts as a Hub and the mobiles devices/ Simulators/Emulators connected will be treated as a Node. Please go through Appium architecture in our previous Blog in case of any doubts.

How to connect device using Java code via Appium?

To access Appium from our java code, we need to include the same “DesiredCapabilities” and its attributes that we used to connect mobile with Appium desktop.

In appium desktop we used GUI, but in our java program we need to include a class called “DesiredCapabilities” form the package “org.openqa.selenium.remote. DesiredCapabilities” to identify the device connected using Key/Value pair.

Have you noticed the package name? Yes we are importing it from Selenium grid support libraries. With the help of method setCapability we can get the mobile device attributes using the interface “MobileCapabilityType”. Syntax Below,

DesiredCapabilities cap = new DesiredCapabilities();

cap.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);

here, DesiredCapabilities is a class and we are creating a strong reference called ‘cap’.

With the help of ‘cap’ we are calling the function/Method ‘setCapability’ and invoking the interface ‘MobileCapabilityType’ which extends its parent ‘CapabilityType’.

Remember the below important facts may be helpful at the time of Interview,

  • DesiredCapabilities is a class
  • Parent class for DesiredCapabilities is MutableCapabilities Class
  • setCapability is a method that is inherited from the class MutableCapabilities
  • MobileCapabilityType is an Interface which extends org.openqa.selenium.remote.CapabilityType

Using which capabilities Appium will find the Mobile Device?

Depends on the platformName, platform version or automationName given in the capabilities, the corresponding bootstrap loader will be triggered from Appium to find the device connected. Set of basic mobile capabilities are listed below.

Below diagram illustrates how Appium communicates with device.

How to open test App using Java code?

I don’t want to showcase any Native apps like calculator or Gallery in this session, We will see some real app in order to understand the functionality. To start our test execution we can follow two approaches,

  1. Using Appium desktop Server
  2. Using Appium command line

In this article, we will figure out using Method 1: Running our test with the help of “Appium Desktop Server”. In future blogs I will let you know how to install and use “Appium command line”

What is AppiumDriver?

AppiumDriver is a Class with a parent “RemoteWebDriver” having “AndroidDriver” and “iOSDriver” as its direct subclass. It means if we declare our driver as an AppiumDriver we can either initiate it as an AndroidDriver or iOSDriver based on our need.

For executing Android based devices we will use “AndroidDriver<?>”  <T extends WebElement> can be “AndroidElement”

For executing Android based devices we will use “AndroidDriver<?>”  <T extends WebElement> can be “iOSElement”

Before starting with the code, Make sure Appium Desktop is running in the background. It should have initiated its Localhost with the given proxy number. Like this,

Note: Once again before running the code, make sure Appium is running in the background else your code will return an exception “org.openqa.selenium.WebDriverException” “Connection refused: connect”.

Please find the sample code for launching an Android app in Java:

In this sample code, we launched the android app in real device with a basic DesiredCapabilities. Note: TestNG annotations are used only to maintain the test.

import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobileCapabilityType;

public class Testengine {
	public static AppiumDriver<?> driver;
	public void startAppium() {
		try {
			DesiredCapabilities cap = new DesiredCapabilities();
			cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
			cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9");
			cap.setCapability(MobileCapabilityType.DEVICE_NAME, "5642c6b9");
			cap.setCapability("appActivity", "com.invoiceapp.InvoiceLaunchScreenAct");
			cap.setCapability("appPackage", "com.invoiceapp");
			cap.setCapability("autoLaunch", false);
			cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 500);
			cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
			driver = new AndroidDriver<AndroidElement>(new URL(""), cap);
		} catch (Exception e) {
	public void test001() {
	public void tearDown() {


In the above code I used TestNG just to maintain the hierarchy. In the @Test annotation I’m simply trying to launch the app. No testing has been performed here. Please find the screenshot below for Appium logs, and read the logs completely to understand how it works.

Please find the sample code for launching an iOS app in Java:

import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;
import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobileCapabilityType;

public class Testengine {
	public static AppiumDriver<?> driver;
	public void startAppium() {
		try {
			DesiredCapabilities cap = new DesiredCapabilities();
			cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
			cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "13.3");
			cap.setCapability(MobileCapabilityType.DEVICE_NAME, "iOSDeviPad");
			cap.setCapability("bundleId", "com.invoice.manager");
			cap.setCapability("udid", "f209a1bc7c7eewf4543rweafdf96645be83fc615bfe3a");
			cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 100);
			cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
			driver = new IOSDriver<IOSElement>(new URL(""), cap);
		} catch (Exception e) {
	public void test001() {
	public void tearDown() {


In Python to Initiate Appium for an iOS application:

Please find the sample code below, to initiate Appium using Pytest framework. This will also work in UnitTest framework it’s up to you on which framework you are using. I prefer to use Pytest because it is having some advanced features when compared with UnitTest. Here also we are following the same desiredCapabilities.

In python, we use dictionary to send the DesiredCapabilities to Appium.

Points to Remember:

  • The capability “Automation_Name” is optional, but it is always a good practice to mention this capability.
  • UDID in iOS and Device_Name for Android are optional if we connect with only 1 device, but when it comes to multiple devices and emulators “Device_Name” is really mandatory else Appium bootloader will pick based on Platform Version.
  • For Android, if we are using Emulators, it is must to mention the “AVD” capability because Appium will prefer the Emulator even if real device is connected (this happens only if both devices and emulator android version are same)
  • Make sure to get the exact application activity for Android based application, else Appium will not initiate the connectivity
  • Sometimes WDA (WebDriverAgent) will uninstall automatically when launching app via Appium, This happens only if we use same device in different Mac machine to perform execution. So it is always good to have a dedicated iPhones for the Mac.

Please let me know in comments whether to include Python syntax also in our blog, else we will focus only on Java.


Naveen AutomationLabs

Blog Contributors:

Author:  Ragavendran

Ragav, having 10+ years of testing experience on which 7 years of rich experience in automation using UFT, Selenium (Java/Python). Expertise in Web and Mobile automation testing using Appium.


Reviewer: Naveen Khunteta 


7. Creating a Framework[Maven project] for Appium – I

So far we have seen about Appium Inspector, also we created a simple test method to launch the app from our java code. Now it’s time to move to next level.

From this session we will cover few advanced topics, which would be helpful for beginners and intermittent test engineers. No worries we will cover step-by-step.

Guys, to understand Appium and its API’s to its root level, It is must to learn the basics of Selenium because at some point we will club both Selenium and Appium libraries. So to be honest, you are not expected to be a Geek in Selenium, but yes Selenium basics are must with any programming language.

Please don’t get confused between Selenium and Appium. As we know both are BINDINGS/Libraries which provided an API for us to perform Automation testing. Bindings means a collections of packages supporting any programming languages. In Java term we can say collections of “Jar” files which can be used with Java.

Appium bindings/libraries with any programming languages are used to automate a mobile application

In other hand, Selenium bindings/libraries with any programming languages are used to automate Web applications. Means both are having its own libraries to perform an operation.

For better understanding, I will take an example, In Selenium library we have an exclusive class called “Actions” using this class we have perform important web page operations like mouseHover(moveToElement), doubleClick, contextClick, dragAndDrop, keyUp, keyDown etc.. But do we need all these actions for Mobile? Do we really need to rightclick and mousehover’s in mobile app? The answer is NO. That’s why Appium is having its own list of libraries, from Appium library we have a class called “TouchActions” where we can perform mobile based operations like Swipe, Scroll, tap, point etc.

It’s all about from which library we are importing into our code

Selenium: “import org.openqa.selenium.interactions.Actions;”

Appium: “import io.appium.java_client.TouchAction;”

I hope we are clear with Appium and Selenium API’s. Now we are in a shape to proceed even further.

Starting now we will focus on creating a Maven project with TestNG and Excel utility to test the App. So that it will be interesting for you guys to follow-up and you will also get the satisfaction of framework design and much more.

How to create a Maven Project?

Before creating a Maven project, we should know about what Maven is and why we need that?

Maven is basically a build tool. Unlike Java project, Maven is having its own folder structure and Dependency mechanism where one can easily maintain the code and update the dependencies in a structured and proper way.

We do have our own video tutorial on what is Maven and how to create a Maven project by Naveen. Please refer the link below for tutorial:

In our tutorial, we are giving preference to Maven framework, because of the some reasons like,

  1. Will save our time and effort from downloading the Appium jars and other must have Jars and link it with our project
  2. We can use the existing Maven folder structure to maintain our class/java files.
  3. With the help of POM file, we can easily maintain our libraries up-to-date
  4. Now a days Maven projects are getting famous in QA fraternity. So it is in must learn list 😊

Creating a Maven project in Eclipse:

Step 1: Open eclipse

Step 2: From the eclipse home page to to Menu bar and click on  

Step 3: Search for the text “Maven”

Step 4: Install the Maven plugin, just by clicking on Install button

Step 5: Once you got the below screen, select all checkboxes and click on “Confirm” button

Installation should be successful. Restart the eclipse.

Step 6: To confirm whether maven plugins are available in Eclipse, that just go to Menu bar and click on New -> Projects

Look in Project wizard for the Name “Maven”. You should get a screen like below,

Step 7: Select “Maven Project” and click on Next

 Step 8: In this screen, you can ignore any pre-defined or existing archtype just by selecting the checkbox “Create a simple project (skip archtype selection)”. We are selecting this checkbox because, there are lot of developers and Maven community guys created pre-defined set of architecture which will be useful for developers with selected POM dependencies. Since we need Maven framework for our Testing, the existing archtypes won’t help so we can simple skip the existing ones and create our own.

Step 9: Click on Next button. Here comes our Major part.

  1. Group id: This is an important field an internal Identity to identify the project.
    1. Naming practice: Reversed domain name of the app under test.
    1. Example: com.invoiceapp (or) org.invoiceapp  [usually lowercases are preferred]
  2. Artifact id: Artifacts means a document, a name of the jar we are going to create. Also the name given in this field is going to be our framework name.
    1. Lower cases are preferred. For our project I’m giving the name as “invoiceapp-regression”
  3. Version: Skip this by selecting the default value 0.0.1-SNAPSHOT. The usage of this field is for version controlling includes giving increments for Major, Minor and low level changes. You can understand the importance and usage of this field when we discuss about the POM file in future sessions.
  4. Packaging: Let it be jar only
  5. You can enter any valid values in “Name” and “Description” fields.
  6. Ignore the Parent Project. This will simply help to inherit the arch from other Maven project.

Now our Maven project and framework skeleton is ready. This is how the initial structure look like.

In any Maven based projects, the below 3 fields are really Mandatory. Without these 3 fields we cannot create or use a Maven project

  1. GroupID
  2. ArtifactID
  3. Version

There is one more field called “Scope”. We will see all these fields in detail in POM Dependency session.

In our next session, we will see

What is a framework? Why we need a Framework

How to add Appium and other utility jar’s in Maven POM file


Naveen AutomationLabs

Blog Contributors:

Author:  Ragavendran

Ragav, having 10+ years of testing experience on which 7 years of rich experience in automation using UFT, Selenium (Java/Python). Expertise in Web and Mobile automation testing using Appium.


Reviewer: Naveen Khunteta 


1. How to Download and Install Appium Desktop on Win and Mac

What is Appium ?

Appium is an open source a cross platform mobile automation tool for use with native, hybrid and mobile web apps. Appium is basically a tool for mobile automation testing and this is not a testing  FRAMEWORK.

Below listed are few reasons to use Appium in our testing framework:

  • Appium will never demand a source code or recompiling of the app on test. 
  • Appium allows to use your preferred programming language, frameworks, and tools.
  • Appium supports programming languages that have Selenium client libraries like Java, Objective-C, JavaScript with node.js, PHP, Ruby, Python, C#, etc
  • Appium also supports cross platform testing frameworks. Single framework to support for iOS and Android, can be achieved using Desired Capabilities and POM.
  • Appium is an open source project and it has a good contributing community.
  • Appium library is having a common class “AppiumDriver” which will support both Androiddriver and IOSDriver. fyi.. It also supports WindowsDriver.
  • Appium is haing a Wrapper program combined with WebDriver Interface that supports vendor provided frameworks like XCUITest, UIAutomator2, Expresso ect.
  • Appium not only supports Real device it also extends its support to Emulators and Simulators
  • Appium is now supporting lot of advanced features like TV automation, Media streaming, Artificial Intelligence, and only emulator supported features like face reading, fingerprint ect..

How to Download and Install Appium Desktop on Win and Mac

Appium Desktop is an application for Windows, Macintosh and linux OS. Appium Desktop is a UI based app with a lot of connectivity and configuration options. It will allows the user to view some advanced options in UI like Inspector for identifying elements, Relaxed security, exporting appium logs and so on..

  • Using a graphical interface for the Appium Server. You can set options, start/stop the server, see logs, etc… Appium Desktop comes with Node runtime files, so no need to separately download and install Node.
  • One of the powerful and main feature on Appium desktop is INSPECTOR. Inspector is the object spy in Applium (like QTP you can spy an element by clicking). Inspector tool will identify the elements along with ID, XPATH and all applicable attributes.

http://appium.io/ is the official website for Appium desktop. One can easily download the latest desktop build of Appium form Downloads sections. Based on preferred the OS we can easily download the build. Hence it is an open source we can download and use it free of cost.

For Windows:

If you are using Windows based OS, then you have to download the .exe file. (ex: Appium-windows-1.15.1.exe). Once downloaded you can install the software by double clicking on the exe file.

On double click on exe file, the below installation screen will popup

Select the 1st radio button if you want appium to be avaialbe for all user who logs in this computer. Else click on 2nd option.  On clicking on “Install” button, installation will begin

Click on “Finish” button to launch the Appium desktop and also to complete the installation process and to quit the installation wizard.

For Mac,

If you are using Mac OS, then you have to download .dmg file so that you can simply move the file under Application to get started. (ex: Appium-mac-1.15.1.dmg). Once downloaded you just need to extract the file and move the build to Applications.

Just click and drag the appium logo to Applications.

Appium also available as an AppImage for Linux. App image is like an executable file for windows. Here in linux no need to install the build, just we need to open the appImage so that your Appium server UI will be prompted.

The good thing in Appium desktop is no UI change for any operation system. UI is built to be stable across platform.

Now we are ready with our Appium desktop to launch and starting the server.

Launching Appium Desktop after Installation for the first time:

Appium desktop UI is very simple and easy to access. Below image represents the home page of Appium Desktop.

In Simple Mode, one can start the Appium server by providing the “Host” and “Port” values. By default Appium REST http interface listener will use the Host and Port “4723”. If any other programs like Jenkins/tomcat are running on a default local server/port then we can change the Port in Appium.

Clicking on “Start Server” button will initiate a local host server with the given port #. You can start seeing logs in Appium desktop like below.

You can also verify the status in any browser by entering the command/URL http://localhost:4723/wd/hub/sessions. Which will give you the current status (same like selenium grid)

By any chance if your firewall is blocking Appium or if you get the below screen, select any or both the checkboxes and click on “Allow access” button. So that Appium can initiate a local host.

How to connect to an Emulator or a real Device with Appium:

Connecting a real device with Appium is very simple. Appium Desired Capabilities will take care of all the connectivity protocols. But before trying to connect we need to make sure all prerequisites are available in the computer. It’s all about configuration and SDK’s

If you want to connect an Android device on a Windows/Mac based OS, then you have to download and install the Android Studio/ Android SDK. Without Android SDK Appium cannot initiate a connectivity to any android based devices. The reason behind this is, Appium will connect to android device in developer debugging mode. Hence to enable the debugging mode “SHELL” commands are inevitable, Commands like ADB, Shell are available only on Android SDK. So to make a connectivity to a real android device “Android SDK” is must.

You can downlad Android SDK on its official website https://developer.android.com/studio. Based on the OS you can download and set the preferences. Once Android studio is installed it is also necessary to install the android SDK based on the device Android version. Ex. My real device is running Android version 9, then I need to install the SDK for Android 9. This can be achieved by AVD in android studio.

“Please use the below steps for creating an Android Emulator”

Step 1: Open android studio

In the home page, you can find “AVD Manager” icon on the top left corner

Step 2: Click on “AVD Manager” icon to get the below screen

Step 3: Create a Virtual Device (Emulator) by clicking the button “ + Create Virtual Device..” then you will be navigated to the below screen

Select the option “Phone” and you can select any device model based on your real device screen size (if needed) and click on “Next”

The below screen will list out all the applicable Android version for the selected device. Then you can click on download as per the android version you need.

Here I have selected “Android Pie” and click on Download.

Accept the license Agreement and click on Next button

Now the selected Android OS will start to download

Click on finish once download is completed.

So we are done with downloading SDK and successfully created Android Emulator.

Click on “Next” button to create an Emulator

Provide any name to the Emulator and click on “Finish”.

On the next time when you click on “AVD Manager” you will get the below screen where you can see the list of AVD’s created

Click on “Launch this AVD” button (Play button) under Actions section to start the Emulator.

Emulator is launched successfully 😊

Android Environmental variables

Once Android SDK is downloaded successfully we can start using ADB and Shell executables from Android SDK. But the problem is windows OS don’t know from where it need to take the executable files. Imaging its like searching a small tool on a big warehouse. So to make the search easier we need to instruct the OS from where we need to utilize the commands, here comes the Environment variables. We need to inform Windows OS to take the executable files from this location and execute my command. So how to configure this ? let’s see

There are many ways to navigate to “Environment Variables” screen, A common way is to click on start menu and type “My Computer” or “My PC”,  then right click on that and select the “properties” option form the menu. Select “Advanced System Settings” to get system properties screen

Click on “Environment Variables” and Select “New” button under “User Variables” section

Now, its time to create “Android_Home” path. Android_Home is nothing but the parent folder wherewe have our SDK and Platform tools available. By default the Android_Home path should be

“C:\Users\current user\AppData\Local\Android\Sdk”

Enter the “Variable Name” as “Android_Home” and “Variable value” with the directory value and click on “OK” button to add the record.

Now “%android_home%” command refers to the directory where our SDK files are located.

It’s time to add “Platform-tools” and “tools” link to our Sytem variables, under “Path” record. For that click on “Path” record and select “Edit” button under System Variables

As I already mentioned, “%android_home%” refers to our SDK directory, now it’s time to add below 3 directories




Just copy and paste it one by one under “Path” record. Like below,

Now we are done with setting up Environment variables for Android. Click on OK button and close all the open windows.

Now open “Command Prompt” and simply type “ADB” and Enter

If you get the text as mentioned in the image, then you successfully configured the Android SDK variable path in our OS. Now we are good to go with Appium to connect to any real device/ Emulators.

Blog Contributors:

Author:  Ragavendran

Ragav, having 10+ years of testing experience on which 7 years of rich experience in automation using UFT, Selenium (Java/Python). Expertise in Web and Mobile automation testing using Appium.


Reviewer: Naveen Khunteta