July 25


What is Appium?

As per official website: Appium is an open-source tool for automating native, mobile web, and hybrid applications on iOS mobile, Android mobile, and Windows desktop platforms. Importantly, Appium is "cross-platform": it allows you to write tests against multiple platforms (iOS, Android, Windows), using the same API.

How does it work?

Appium test script written in IDE will interact with the Appium Server which is nothing but the node server with the specified IP address and port number. Node server again passes the request to mobile devices or emulators using the uiautomator or XCUITest as a JSON format. All the UI elements associated with the mobile application can be controlled by using the appium client which is nothing but the derived one of selenium.

Note: Remember using Windows only Android can be automated while in iOS both Android and iOS can be automated.

Installation and setup

  1. Install Java 8 and setup environment variable.
  2.  Install Maven and setup environment variable.
  3. Install Android studio for android SDK packages.
  4.  Setup android environment variable.
  5. Creating an emulator via android studio.
  6. Enabling Developer mode option in android phone.
  7. Install PDANet (universal driver) to connect with Android devices.
  8. Install Xcode, HomeBrew, Carthage, appium-xcuitest-driver for (Mac only).
  9. Install Appium via npm.
  10. Install Appium via installer.
  11. Install Appium Doctor.

Install Java 8 and setup environment variable.

Download Java 8 from https://www.oracle.com/java/technologies/javase-jdk8-downloads.html and install it.

Next step is to set environment variables. We will set JAVA_HOME and the path variable.

For Mac:

For Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME variable to /usr/libexec/java_home, just export $JAVA_HOME in file ~/. bash_profile or ~/.profile.

Open terminal and type (You must be familiar with vi editor commands).

$ vim .bash_profile

Add below lines

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=${JAVA_HOME}/bin:$PATH

Save the file

Then run below command.

$ source .bash_profile

To confirm if it is set correctly type

$ echo $JAVA_HOME

It should return below path


Type “java -version” to confirm it.

For Windows:

From windows search bar type advanced system settings.

It will open System Properties window.

Select advance tab and click environment variable.

From system variable, click to new button and enter variable name as JAVA_HOME and value as path to JDK installed.

Next we have to edit the system path variable.

 click on New button, and add this %JAVA_HOME%bin. Click OK

From command prompt type java -version. The output show java version example:

 Install Maven and setup environment variable.

Method 1: Via homebrew for mac only.

Run below command to install homebrew.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

To install maven

brew install maven

Method 2: Manual install

1.         Download maven apache-maven-x.x.x-bin.zip from path https://maven.apache.org/download.cgi and extract to your local directory.

Setting up Maven environment variable.

For Mac:

1.         The variable should be updated to bash_profile or ~/.profile.

2.         Open terminal and run below command.

$ vim .bash_profile

export MAVEN_HOME=/Applications/apache-maven-x.x.x


$ source .bash_profile

$ echo $MAVEN_HOME


3.         After setting environment variable run mvn -version to confirm if maven is set properly.

For Windows:

From windows search bar type advanced system settings.

It will open System Properties window.

Select advance tab and click environment variable.

From system variable, click to new button and enter variable name as MAVEN_HOME and value as path to the Maven folder present.

Next we have to edit the system path variable.

 click on New button, and add this %MAVEN_HOME%bin. Click OK

From command prompt type mvn -version. The output show maven

Install Android studio for android SDK packages.

Android Studio Installation and download SDK packages. (Common for both Mac and Windows)

1.         Download Android studio from https://developer.android.com/studio as per your OS and install.

2.         Launch android studio.

3.         Create a dummy project, after Android studio is launched.

4.         Go to Tools  >> SDK manager. In the latest version of Android Studio, the 'SDK Manager' is an icon on the menu. This opens up the SDK manager dialog box.

5.         Select the 'Android SDK' link under 'System Settings' on the left pane, and choose 'SDK Tools' and check the box “Intel x86 Emulator Accelerator” if not checked.

  1.  Uncheck "Hide Obsolete Packages"  option.
  2.  Tick mark "Android SDK Platform -Tools (obsolete)" .
  3.  Click on Apply -> click on OK Button. It will start downloading android sdk to your system.
  4. After installation cross check the path where you are able to see all sdk components.

6.         Note down the Android SDK location path from sdk manager and copy to a notepad.

7.         For ex: /Users/username/Library/Android/sdk

8.         Click OK to download start, it will take some time to download all the components.

9.         Close SDK manager.

Setup android environment variable.

For Mac: 

Just like we set JAVA_HOME, set the Android environment variable.

Open terminal and run below commands

$ vim .bash_profile

export ANDROID_HOME=/Users/username/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH

Save the file.

$ source .bash_profile

Open terminal and type adb version to verify the environment is set properly.

For Windows:

Steps for adding environment in windows are same as above for JAVA_HOME and MAVEN_HOME.

Add ANDROID_HOME and value to sdk location under system variable.

Variable Name: ANDROID_HOME

Variable Value: C:UsersxxxxxAppDataLocalAndroidSdk

Then add %ANDROID_HOME%platform-tools and %ANDROID_HOME%tools in path variable.

For Mac only.

So if we add all environment variables then the file will look like this. Yes. there are some extra variables  added which will come to know as you start automating.

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=${JAVA_HOME}/bin:$PATH
export ANDROID_HOME=/Users/$(whoami)/Library/Android/sdk
export ANDROID_AVD_HOME=/Users/$(whoami)/.android/avd
export PATH=$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_SDK_ROOT/emulator:$PATH
export M2_HOME=/Users/$(whoami)/Downloads/Softwares/Maven
export PATH=$PATH:$M2_HOME/bin

Creating an emulator via android studio.

  1. Open Android studio.
  2. Go to Tools >> Android >> AVD Manager.
  3. From Virtual configuration window select >> Create a new device.
  4. Select the device you want to download. Ex. Pixel
  5. Select OS version as per your requirement. Ex.Oreo Android 8.0 with Google APIs.
  6. Accept the licence agreement.
  7. It will start downloading the image. (Takes time depending on network speed and size).
  8. After download start the emulator from avd manager  device list.
Enabling Developer mode option in android phone/Emulator.

Go to settings and scroll down to About phone  option.

Scroll down to Build number and tap multiple times. You can see the toast message “You are now x steps away to being a developer”.

After tapping 5-7 times when you see “No you are a developer” , which confirms that you have enabled developer mode.

To confirm go back to the previous page and select System >> Advanced >> Developer option.

From Developer option scroll down and enable USB debugging, Verify apps over USB option.

Install PDANet (universal driver) to connect with Android devices.

To interact with devices and system we need a USB driver, usb driver is different with respective to android devices. But we can install one driver which will work across all the android devices.

  1. Go to http://pdanet.co/install/.
  2. Download the installer as per your operating system and install it.

Install Xcode (For Mac only)

Open App store and search for xcode then install it.

Install HomeBrew(For Mac Only)

Open terminal.

And type /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

This will install homebrew in your mac machine.

For more information go through https://brew.sh/

There is also a dependency, made necessary by Facebook's WebDriverAgent, for the Carthage dependency manager. If you do not have Carthage on your system, it can also be installed with Homebrew

brew install carthage

For real devices we can use xcpretty to make Xcode output more reasonable. This can be installed by gem install xcpretty

More information at : https://www.npmjs.com/package/appium-xcuitest-driver

For appium-xcuitest-driver installation refer below link.


Appium Setup:

There are two ways to install such as via npm and installer.

Installing via npm which requires node.js installation.Install Node.js

1.         Download node.js as per your operating system from https://nodejs.org/en/download/.

2.         After successful installation we have to set the environment variable for Windows OS but for mac it is not needed.

Open command prompt or terminal and type “npm-v” it returns the version number which confirms that node.js is configured properly.

Appium Installation:

1.         Open command prompt or terminal in administrator mode and run below command.

2.         Run npm install -g appium  to install globally, if you want to install a particular version then run npm install -g appium@1.16.0  This will trigger the installation and it will take 5-10 mins depending on your network and RAM size.

3.         After successful installation run appium command in terminal/command prompt.

4.         If this returns below result, then Appium is successfully installed to your system.

Install via Appium installer.

You can download appium installer from appium official website.

Go to http://appium.io/downloads.html and click to download.

It will take you to https://github.com/appium/appium-desktop/releases/tag/vx.xx.x

Select the installer as per your operating system and download.

Appium-windows-x.xx.x.exe file is for windows and Appium-mac-x.xx.x.dmg file for mac.

Install it. Then run it will open one window , hit the start button  appium server console.

Install appium doctor

This tool is used to diagnose and fix common Node, iOS and Android configuration issues before starting Appium.

To install run below command in terminal

npm install appium-doctor -g

To execute, run  appium-doctor command.

This will give you a report as below, if any configuration is missing please fix them and proceed.

Getting familiar with ADB

What is ADB?

Adb stands for Android Debug Bridge. It is a client server program which allows us to communicate with an Android device or an Emulator using command line.

A client, which runs on our machine. We can invoke a client by issuing an adb command.

A daemon, which runs as a background process on each emulator or device instance. It by default runs on port number 5037

A server, which runs as a background process on our machine. It manages communication between the client and the adb daemon running on an emulator or device.Where is it located?

After successful download of android sdk, the adb tools comes with SDK inside the platform-tools folder. You can get the path using “which adb” command.


Before running adb commands, ensure that USB debugging is enabled and the device is connected to the system using USB.

List of ADB commands and usage:

adb devices : To find out list of connected devices.

Offline : The device is not connected or not responding

device : The device is connected to adb server

no device : There is no device connected to adb server

adb usb → To switch to USB mode.

adb tcpip [port no] → To start TCP IP Connection.

adb connect [device IP address] → To connect devices over wifi.

adb version → To check ADB version.

adb logcat → To display logs of connected devices.

adb logcat > path of the filelog.txt → To store adb logs in text file.

adb kill-server → To kill adb server.

adb start-server → To start adb server. 

adb shell → To run the terminal of host Android device. Below command can be used with adb shell command.

getprop ro.product.model → This command get’s the attached device model no

getprop ro.build.version.release → This command get’s the android build release version i.e. 4.4.2/4.4.4

getprop ro.build.version.sdk → This command get’s the device api version i.e. 19,20,21,22

pm list packages –f → To get app package of installed apps.

How to install apk using abd command?

  1. Get the apk file from dev or any other source.
  2. Paste in your system location.
  3. Connect your device and your device should have usb debugging enabled.
  4. Open command prompt .
  5. Type below command (enter your apk file name without angular bracket).

    Note: Make sure when you execute you have .apk extension mentioned.
    adb install <YourApkName>.apk
    If multiple device connected then how to installed into a particular device.

    1. Follow 1-4 steps from solution 1.
    2. Type <adb devices> in command prompt.
    3. This will list out the connected device.
    4. Note the device id and enter below command

      adb -s <YourDeviceId> install <YourApkName>.apk

      If Apk Installation failed due app is already exists,
      Enter command prompt and enter below command.

      adb install -r <YourApkName>.apk

      adb uninstall [package name or apk’s path] → To uninstall apk of package.

      adb install -r [apk] → To command to update the app.

      Adb command for file sharing.
      adb pull <source folder><destination folder>

      Command to send files from computer to phone

      adb push <source folder><destination folder>

      Understanding Desired Capabilities

      DesiredCapabilities is a JSON object in the form of a key and value pair sent from client to server. It has basic set of information to create automation sessions. Let's look out some essential desired capabilities.

      cap.setCapability(MobileCapabilityType.DEVICE_NAME, "0797818a87d4f5cb");
      It shows the kind of mobile device or emulator used for automation. Such as “Samsung S10” , “Google Pixel”, “Android Emulator”, “iOS Simulator”.

      cap.setCapability(MobileCapabilityType.VERSION, "9.0");
      The device operating system such as 7.0, 9.0, 10, 11 etc

      cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
      cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
      The device OS platform such as iOS or Android.

      cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
      The automation engine, for android mention UIAutomator2 and for iOS it is XCUITest

      cap.setCapability(MobileCapabilityType.UDID, "E5EB4A6D-32AC-4B2A-9AA8-3BC25D8FC0BF");
      Unique device identifier of the connected physical device. We will later learn how to get this for android and iOS.

      cap.setCapability(MobileCapabilityType.APP, “//Path to build file”));
      The absolute or local path for build. For android it is .apk and for iOS .ipa and .app

      Don't reset the app before this session. It could be true or false.

      It performs a complete reset, it could be true or false.

      cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis");
      cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".ApiDemos");

      The above capabilities are mainly used to invoke installed android app.  App package is the java package of an app on which you want to run. App activity is the android activity you want to launch from your package. Generally apps start from .splashActivity. We will see how we can get it later.
      In the case of iOS if you want to invoke installed app then use budleID with app desired capabilities.

      Example: cap.setCapability(MobileCapabilityType.APP,"com.example.apple-samplecode.UICatalog");
      We will discuss how to get this later.

      How to get the app package and activity of an app?
    1. Connect your device and make sure its detected by adb.
    2. Then open command prompt type adb shell
    3. Now type dumpsys window windows | grep -E 'mcurrentFocus|mFocusedApp' 
    4. "Do not press enter now". Launch the app in your device and at the same time execute the above command it will list out the package name and the current activity. Sample output:

      C:UsersSiddharth>adb shell
      dreamlte:/ $ dumpsys window windows | grep -E 'mcurrentFocus|mFocusedApp'mFocusedApp=AppWindowToken{6ec47ae token=Token{e3aa829 ActivityRecord{59aa1b0d0 u0 io.appium.android.apis/.ApiDemos t2017}}}
      dreamlte:/ $

      From above output :
      "io.appium.android.apis" is your app package.
      ".ApiDemos" in your app activity.

      App package and app activity to be used in desired capabilities as

      DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis"); cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".ApiDemos");

      Official link: http://appium.io/docs/en/writing-running-appium/caps/How to get bundleId (for iOS only)

      Appium provides bundleID to identify the iOS application. Generally in organizations we can get it the same from developers. If the developer is not unknown and you are working on public application then refer below steps. 

      A . Using Command prompt.
      1. Get the file (.ipa or .app) file to your local. Here we will take example of UICatalog app.
      2. Run below command.
      3. osascript -e 'id of app "/path to the app/UIKitCatalog.app"'
      4. It will will give you the output as com.example.apple-samplecode.UICatalog