Setup Appium on Mac OS for Android and iOS App Automation [2021 Update]

Appium is an open-source test automation framework for use with native, hybrid, and mobile web apps.
It drives iOS, Android, and Windows apps using the WebDriver protocol.

The biggest challenge is to set up the required environment required to start your automation, it will take 2–3 days without proper steps, so I have made a proper guide to get the setup ready as soon as possible😊 ❤️

Step 1: Change to terminal to bash in order for some functionalities to work.

Open the Terminal

To change a user account’s default shell on macOS, simply run the chsh -s (change shell) command in a Terminal window.

Change the default shell to Bash by running the following command.

$ chsh -s /bin/bash

Enter your MAC user account’s password when prompted.

Close the Terminal window and reopen it. You’ll be using Bash instead of Zsh.

Step 2: Install Homebrew.

Homebrew installs the stuff you need that Apple (or your Linux system) didn’t.

Homebrew installs packages to their own directory and then symlinks their files into /usr/local.

Homebrew complements macOS (or your Linux system). Install your RubyGems with gem and their dependencies with brew.

Type following command in terminal to install Homebrew

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

Step 3: Install Java 8 (OpenJDK version “1.8.0_265”), Using Home brew.

Type following command in terminal to install adoptopenjdk8

$ brew install --cask adoptopenjdk/openjdk/adoptopenjdk8

Verify installation by Typing the following command in Terminal.

$ java -version

Step 4: Download and install Android Studio, from below link and move to applications folder of MAC.

https://developer.android.com/studio

Step 4.1: Double click to install the downloaded DMG file and move to applications folder

Step 4.2: Open the app click on Next, and configure and Click on finish

Step 4.3: Install other SDK versions as required for your project.

Example : SDK verisons for api 30, S preview

Step 5: Install Xcode from app store.

  1. Open the App store on MAC.
  2. Search for Xcode.
  3. Click on the Install Button and wait for install to finish.

Step 5.1: Open Xcode from applications folder and install required components.

Install Command Line Tools if you haven’t already.

Type following command in terminal to install

$ xcode-select --install  

Type following command in terminal to set Proper “Xcode” Verison, Required for Build Process.

$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Step 5.2: Install Carthage.

Carthage is intended to be the simplest way to add frameworks to your Cocoa application.

Carthage builds your dependencies and provides you with binary frameworks, but you retain full control over your project structure and setup. Carthage does not automatically modify your project files or your build settings.

https://github.com/Carthage/Carthage

First, change the permissions and accept the Xcode license as shown below commands.

$ sudo chown -R $(whoami) /usr/local/share/man/man5 /usr/local/share/man/man7
$ sudo xcodebuild -license accept

Then, install Carthage by typing following command in terminal.

$ brew install carthage

Step 6: Install Node via Homebrew.

Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine.

https://nodejs.org/en/

Type following command in terminal to install node.

$ brew install node

Check the Node and NPM version by Typing following commands in terminal

To check node version.

$ node -v
v14.14.0

To check npm version.

$ npm -v
6.14.8

Step 7: Install Latest Appium and required dependencies globally using NPM.

Appium is an open source test automation framework for use with native, hybrid and mobile web apps.
It drives iOS, Android, and Windows apps using the WebDriver protocol.

https://appium.io

Run following command in terminal to install appium.

$ npm install -g appium

Step 7.1: Install WD required for Appium by using following command.

WD is node.js Webdriver/Selenium 2 client

This library is designed to be a maleable implementation of the webdriver protocol in Node, exposing functionality via a number of programming paradigms.

Run following command in terminal to install wd.

$ npm install wd

Step 7.2: Install Appium Doctor

Appium Doctor checks most of the preconditions for Appium to run successfully. Attempts to diagnose and fix common Node, iOS and Android configuration issues before starting Appium.

Run following command in terminal to install appium-doctor.

$ npm install -g appium-doctor

Note : If you want to install a specific version of appium you can run below command.

$ npm install -g appium@1.1x.x

Step 8 : Set required paths for JAVA_HOME in .bash_profile for below.

Type following command in terminal to open nano and set JAVA_HOME.

$ nano .bash_profile

Set Java home variable as below in .bash_profile.

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

Save and close the opened .bash_profile file.

Re-Open Terminal and run the source command to apply the changes.

source ~/.bash_profile

Now we can check the value of the JAVA_HOME variable.

echo $JAVA_HOME

The result should be the path to the JDK installation:

/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

Step 9: Set required paths for ANDROID_HOME in .bash_profile for below.

Type following command in terminal to open nano editor and set Android Home along with the path to below-required tools.

  1. platform-tools.
  2. tools.
  3. build-tools.
$ nano .bash_profile
export ANDROID_HOME=/Users/kchetan/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/platform-tools/bin:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/build-tools/30.0.2:$PATH
export PATH=$ANDROID_HOME/build-tools/30.0.2/bin:$PATH

Save and close the opened .bash_profile file.

Re-Open Terminal, and run the source command to apply the changes.

source ~/.bash_profile

Now, we can check the value of the ANDROID_HOME variable.

echo $ANDROID_HOME

The result should be the path to the Android SDK installation.

/Users/kchetan/Library/Android/sdk

Step 10: Install Webpack

Webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.

To install webpack run the below command.

$ npm i -g webpack

Step 11: Install libimobiledevice.

libimobiledevice is A cross-platform FOSS library written in C to communicate with iOS devices natively.

https://libimobiledevice.org

To install libimobiledevice run the below command.

$ brew install libimobiledevice

Step 12: Install ios-deploy

Install and debug iOS apps from the command line. Designed to work on un-jailbroken devices.

https://www.npmjs.com/package/ios-deploy

To install ios-deploy run the below command.

$ npm install -g ios-deploy

Step 13: Install cmake

CMake is an open-source, cross-platform family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice. The suite of CMake tools were created by Kitware in response to the need for a powerful, cross-platform build environment for open-source projects such as ITK and VTK.

To install cmake run the below command.

$ brew install cmake

Step 14: Install opencv4nodejs

Opencv4nodejs allows you to use the native OpenCV library in nodejs. Besides a synchronous API the package provides an asynchronous API, which allows you to build non-blocking and multithreaded computer vision tasks. opencv4nodejs supports OpenCV 3 and OpenCV 4.

To install opencv4nodejs run the below command.

$ npm install -g opencv4nodejs

This takes a while to install, Have Coffee ☕️

Step 15: Install applesimutils

A collection of utils for Apple simulators.

To install applesimutils run the below command.

$ brew install wix/brew/applesimutils

Step 16: Install ios-webkit-debug-proxy

The ios_webkit_debug_proxy (aka iwdp) proxies requests from usbmuxd daemon over a websocket connection, allowing developers to send commands to MobileSafari and UIWebViews on real and simulated iOS devices.

https://github.com/google/ios-webkit-debug-proxy

To install ios-webkit-debug-proxy run the below command.

$ brew install ios-webkit-debug-proxy

Step 17: Install osxfuse

FUSE implements a mechanism that makes it possible to implement a fully functional file system in a user-space program on macOS. It provides multiple APIs, one of which is a superset of the FUSE API (file system in user space) that originated on Linux. Therefore, many existing FUSE file systems become readily usable on macOS.

https://osxfuse.github.io

To install osxfuse run the below command.

$ brew cask install osxfuse

Step 18: Install ifuse

This allows mounting various directories of an iOS device locally using the FUSE file system interface.

Some key features are:

  • Media: Mount media directory of an iOS device locally
  • Apps: Mount sandbox container or document directory of an app
  • Jailbreak: Mount root filesystem on jailbroken devices (requires AFC2 service)
  • Browse: Allows to retrieve a list of installed file-sharing enabled apps

https://github.com/libimobiledevice/ifuse

To install ifuse run the below command.

$ brew install ifuse

Step 19: Install mjpeg-consumer

node.js transform stream implementation that consumes http multipart mjpeg streams and emits jpegs.

https://www.npmjs.com/package/mjpeg-consumer

To install mjpeg-consumer run the below command.

$ npm i -g mjpeg-consumer

Step 20: Install ffmpeg

A complete, cross-platform solution to record, convert and stream audio and video.

https://ffmpeg.org

To install ffmpeg run the below command.

$ brew install ffmpeg

Step 21: Install set-simulator-location

This is a simple CLI for easily setting the location of the currently running iOS Simulator.

https://github.com/lyft/set-simulator-location

To install set-simulator-location run the below command.

$ brew install lyft/formulae/set-simulator-location

Step 22: Install fb-idb

The “iOS Development Bridge” or idb, is a command line interface for automating iOS Simulators and Devices. It has three main priniciples:

  • Remote Automation: idb is composed of a "companion" that runs on macOS and a python client that can run anywhere. This enables scenarios such as a "Device Lab" within a Data Center or fanning out shards of test executions to a large pool of iOS Simulators.
  • Simple Primitives: idb exposes granular commands so that sophisticated workflows can be sequenced on top of them. This means you can use idb from an IDE or build an automated testing scenario that isn't feasible with default tooling. All of these primitives aim to be consistent across iOS versions and between iOS Simulators and iOS Devices. All the primitives are exposed over a cli, so that it easy to use for both humans and automation.
  • Exposing missing functionality: Xcode has a number of features that aren’t available outside it’s user interface. idb leverages many of Private Frameworks that are used by Xcode, so that these features can be in GUI-less automated scenarios.

https://github.com/facebook/idb

To install fb-idb run the below command.

$ brew tap facebook/fb
$ brew install idb-companion
$ pip3.6 install fb-idb

Please note : 📝 Use Python 3.6 to install fb-idb using pip3.6 or else it wont be detected properly

Step 23: Download and set path for Bundletool

bundletool is the underlying tool that Gradle, Android Studio, and Google Play use to build an Android App Bundle or convert an app bundle into the various APKs that are deployed to devices. bundletool is also available to you as a command line tool, so you can recreate, inspect, and verify Google Play’s server-side build of your app’s APKs.

23.1 Download bundletool.jar from

https://github.com/google/bundletool/releases

23.2 Rename it to bundletool.jar

23.3 Create folder ~/Library/Android/sdk/bundle-tool in Mac

23.4 Move bundletool.jar to this path and make it executable with chmod +x bundletool.jar

23.5 Add $ANDROID_HOME/bundle-tool to the path editing .bash_profile

nano .bash_profileexport PATH=$ANDROID_HOME/bundle-tool:$PATHsource .bash_profile

Step 24 : Run appium-doctor to verify everything is proper

To view appium-doctor output run the below command.

appium-doctor

info AppiumDoctor Everything looks good, bye!

Step 25 : Run appium and have fun Automating iOS / Android Apps.

If everything is successful, then try to start appium using below command.

$ appium

Voila, you are good to Start the scripting 😃 😀

Cheers 🍻 🥂 🍺

Automation Test Engineer by Profession, Traveller by the Weekend

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store