Setting up Appium with Java on OS X

Olya Kovalenko
5 min readNov 1, 2017

--

Installing and configuring Appium is not a simple process because you need to download and install many different tools. In this article, I will try to describe all the steps to simplify this process.
I’ve chosen Java programming language for automation, and my tutorial will focus on it.

Few words about Appium:
Appium is an open-source and cross-platform tool that helps to automate Mobile Application testing for Android and iOS platforms. Also, Appium supports Native, Mobile Web, and Hybrid Applications.

Performs automation on Android and iOS devices (phones and tablets) using Selenium Webdriver. You can use the same Webdriver bindings for both web and mobile. Supports all languages that have Selenium client libraries including, Java, C#, Ruby, Python, Javascript (Node) and PHP.

Preconditions to use Appium

  1. Java JDK: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  2. Android Studio https://developer.android.com/studio/index.html
  3. IntelliJ IDEA https://www.jetbrains.com/idea/
  4. Selenium jar http://docs.seleniumhq.org/download/
  5. Selenium Standalone Server jar http://www.seleniumhq.org/download/
  6. Appium client libraries http://appium.io/downloads.html
  7. Appium desktop http://appium.io/
  8. XCode from App Store (should be Xcode 8+)
  9. Application (ipa or apk)

Install Java JDK

Open http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html Select ‘Accept License Agreement’ and Click Download link corresponding to Mac OS X.

Install Android Studio

Open https://developer.android.com/studio/index.html#downloads

Tap on “Download Android Studio”

Make sure that latest Android SDK API is installed (Preferences -> System Settings -> Android SDK). Open the SDK manager and download the relevant files. Open the Android Virtual Device Manager and create the virtual devices.

Download Selenium WebDriver Jars

Open the official Selenium website http://www.seleniumhq.org/download/

In section “Selenium Client & WebDriver Language Bindings” you can find download links next to different languages. Download and install Java specific client driver.

Download Appium Java Client Jar

Open the official Appium website http://appium.io/downloads.html.

Click on the Java binding and download “jar” file from the Maven Central Repository https://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.appium%20a%3Ajava-client

Setup Appium Environment

Open Terminal and install brew. Brew is an amazing package manager for OS X and installing packages and updating it will be breeze once you install brew:

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

$ brew doctor

Check ruby version:

$ ruby --version

Install node.js

Download installer: https://nodejs.org/en/download/ and run in Terminal:

$ brew update

$ brew upgrade node

$ brew install node

$ npm install -g npm

Check node and npm versions (should be v6 or better):

$ node --version

$ npm --version

Install build automation system

You can use one of the build automation tool Gradle or Maven.

Gradle is an open source build automation system. You can download the latest release and install manually using installation tutorial https://gradle.org/releases/.

Check Java version (should be v7 or better):

$ java -version

java version “1.8.0_144”

Or install Gradle in Terminal

$ brew update && brew install gradle

Check Gradle version:

$ gradle -v

Maven is a build automation tool used primarily for Java projects.

Install Maven (maven 3.1.1 or higher) http://maven.apache.org/download.cgi

Or install Maven on OS X 10.12 in Terminal

$ brew update

$ brew install maven

Check Maven version:

$ mvn -version

Update system preference

Open bash_profile in terminal:

$ nano ~/.bash_profile

paste following:

export ANDROID_HOME=/Users/User_name/Library/Android/sdk

export PATH=$ANDROID_HOME/platform-tools:$PATH

export PATH=$ANDROID_HOME/tools:$PATH

export JAVA_HOME=$(/usr/libexec/java_home)

export PATH=$JAVA_HOME/bin:$PATH

export PATH=”/Users/User_name/Desktop/apache-maven-3.5.0/bin”:$PATH

export PATH=$PATH:/opt/gradle/gradle-4.2.1/bin

Save and exit

Check that JAVA_HOME and ANDROID_HOME is set:

$ echo $JAVA_HOME

$ echo $ANDROID_HOME

Installing Appium desktop version

Go the Appium website http://appium.io/ and download appium-desktop.

And clone Appium

$ git clone git://github.com/appium/appium.git

$ cd appium

$ npm install

$ npm install wd

One of the alternative way to install Appium is to install via npm (Node JS Package Manager).

In Terminal install Appium command line:

$ npm install -g appium

$ npm install wd

To verify that all of Appium’s dependencies are met you can use appium-doctor. Install it with

$ npm install -g appium-doctor

$ appium-doctor

$ appium-doctor --ios

$ appium-doctor --android

Install Dependencies

Install a cross-platform software protocol library and tools to communicate with iOS devices natively

$ brew install libimobiledevice --HEAD

There is also a dependency, made necessary by Facebook’s WebDriverAgent, for the Carthage dependency manager.

$ brew install carthage

Deviceconsole allows analyzing crash logs and console output from the device

$ npm install deviceconsole

Install and debug iPhone apps from the command line, without using Xcode

$ brew install ios-deploy

Xcpretty is a fast and flexible formatter for xcodebuild

$ gem install xcpretty

If Xcode Command Line Tools are NOT installed

$ xcode-select --install

Or use instructions by following link https://www.embarcadero.com/starthere/seattle/mobdevsetup/ios/en/installing_the_commandline_tools.html

You need to authorize use of the iOS Simulator. If you’re only testing Android, this can be skipped.

$ npm install -g authorize-ios

$ authorize-ios

Start Appium.

$ node .

Once the Appium server is running you will see some logs in the app screen or alternately hit the below url to check the status.

http://localhost:4723/wd/hub/status

Stop Appium.

Press CTRL+C in the same Terminal window to stop Appium server.

--

--