, ,

Appium Server is really tricky to setup in Mac OS as there are multiple components to be integrated. I have given the steps to setup Appium Server for Android platform. Using the below steps, the reader can start the Appium Server programmatically, run the tests in Emulator. Feel free to contact me in case of any issues during setup. Constructive feedback is welcome to improve the post which helps users.

Android Appium
Steps to setup Appium Android. I have given the steps below for Mac OS & Windows. Hope Linux follows the same pattern as that of Mac.

Step 1 : Download & Install Eclipse





Step 2 : Download & Install Appium

Mac & Windows users, choose the respective appium binary at


Mac users move the Appium.app to the Applications folder.

Step 3 : Need to install a Emulator of your choice. I prefer Genymotion.

Step 4 : Setup Genymotion : In Genymotion or any emulator, Create a Android Virtual Device of your choice. I choose to create Samsung Galaxy S4. Once the virtual device is created, try installing your android app, by drag and drop over the Virtual Device’s home screen.

Step 5 : Install Android SDK. Android Studio is not required and just the Android SDK is sufficient. We can add the required packages later using Android SDK Manager. Download the SDK tools appropriate for your platform.


  • On Mac or Linux, open a terminal and navigate to the tools/ directory in the Android SDK, then execute android sdk.
  • Under Tools, Make sure you do have Android SDK Tools, Android SDK Platform-tools, Android SDK Build-tools installed.
  • Also, install the Android Version (5.0.1) in which your application works.

Step 6 : Environment variables if not created properly will create issues when the Appium server is started from the eclipse. So, please follow the below steps diligently.

In Mac, setting up environment variables in ~/.bash_profile, ~/.profile or using any export command in the Terminal window will be available only for Terminal application.

If the Appium server is to be started from Eclipse, ANDROID_HOME env variable should be setup using the below procedure.

  • ANDROID_HOME environment variable setup. Mac users please follow the below link.


  • Create PATH variable using the same steps as above and add $ANDROID_HOME/platform-tools/, $ANDROID_HOME/tools/, $ANDROID_HOME/build-tools to your PATH variable.

Step 7 : Setting up Eclipse

  • Create a Maven project in Eclipse – File > New > Project > Maven > Maven Project
  • Add the below dependencies in your pom.xml


  • Appium Server programmatically run from Eclipse using the below code in the Project.

import io.appium.java_client.android.AndroidDriver;

import java.io.IOException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecuteResultHandler;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteException;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class SetupAndroidAppium{

public static AndroidDriver driver;

static DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
static DefaultExecutor executor = new DefaultExecutor();

public static void setUp() throws Exception {

System.out.println(“****************setUP Starts****************”);

System.out.println(“ANDROID_HOME : “+System.getenv(“ANDROID_HOME”));
System.out.println(“PATH : “+System.getenv(“PATH”));

resultHandler = new DefaultExecuteResultHandler();
executor = new DefaultExecutor();
// executor.execute(killNode,resultHandler);
// executor.execute(killPlayerEmulator,resultHandler);
// executor.execute(killADB,resultHandler);

// CommandLine command = new CommandLine(“/bin/sh -c”);
// command.addArgument(“/Applications/Appium.app/Contents/Resources/node/bin/node”,false);

CommandLine command = new CommandLine(“/Applications/Appium.app/Contents/Resources/node/bin/node”);

command.addArgument(“/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js”, false);
command.addArgument(“–address”, false);
command.addArgument(“–port”, false);
command.addArgument(“–bootstrap-port”, false);
// command.addArgument(“–no-reset”, false);

executor.execute(command, resultHandler);


DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(“platformName”, “Android”);
// capabilities.setCapability(“platformVersion”, “4.4.2”);
// capabilities.setCapability(“browserName”, “android”);

/* appPackage & appActivity is not mandatory as the Appium will inspect the .apk file for the default package and the activity
* Issues if any, please set it explicitly.
* */
// capabilities.setCapability(“appPackage”, “com.migmeplayground”);
// capabilities.setCapability(“appActivity”, “com.projectgoth.activity.MainActivity”);
capabilities.setCapability(“app”, “<PATH/TO/YOUR/ANDROID/APK>.apk”);
// capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “device”);

// The device name could be found by running the command adb in the terminal window.
* android-sdk-macosx$ adb devices
List of devices attached device
* */
capabilities.setCapability(“deviceName”, “device”);

driver = new AndroidDriver(new URL(“;),capabilities);


driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);

System.out.println(“****************setUp Ends****************”);

public static void main(String args[]){


System.out.println(“****************main Starts****************”);
System.out.println(“****************main Ends****************”);
catch(Exception e){



public static void tearDown() throws Exception {
System.out.println(“****************tearDown Starts****************”);

System.out.println(“****************tearDown Ends****************”);

public static void test01() throws InterruptedException {

System.out.println(“****************test01 Starts****************”);

driver.findElement(By.xpath(“YOUR TESTS HERE”));
driver.findElement(By.xpath(“YOUR TESTS HERE”));

System.out.println(“****************test01 Ends****************”);


* Method to launch the emulator programmatically
* */

public static void launchEmulator() throws ExecuteException, IOException{

System.out.println(“****************launchEmulator Starts****************”);

CommandLine launchEmul = new CommandLine(“/Applications/Genymotion.app/Contents/MacOS/player”);

// command.addArgument(“–address”, false);
// command.addArgument(“”);
launchEmul.addArgument(“–vm-name”, false);


executor.execute(launchEmul, resultHandler);
System.out.println(“****************launchEmulator Ends****************”);

private static void killNodeAdbPlayer() throws ExecuteException, IOException, Exception{
System.out.println(“****************kill Node Adb Player Starts****************”);

CommandLine killNode = new CommandLine(“kill -9 $(lsof -i | grep 6723 | awk ‘{print $2}’)”);
CommandLine killPlayer = new CommandLine(“kill -9 $(lsof -i | grep 6724 | awk ‘{print $2}’)”);


System.out.println(“****************kill Node Adb Player Ends****************”);