Setting Up Appium On A Mac

Mike LaPeter
Nov 4, 2019 · 3 min read

Note: These are primarily my notes, and meant to be a companion to the official appium getting started docs, not a replacement. Before getting started, make sure you’re on the right version of node, appium requires 10+.

Appium Setup:

npm install -g appiumnpm install -g appium-doctor

That’s it! You can verify it works by starting the appium server by typing appium in your terminal (you can then stop it for now). If that sounded too easy, you’re right — getting the drivers and Android and iOS simulators setup properly is what took me the most time.

Android Setup:

We’ll start with android to follow along with the official Appium Getting Started Docs. Start by running appium-doctor --android to see where you’re at — you’re probably missing a few things. To actually run android tests on appium, you’ll need a driver. The docs suggest UiAutomator2 Driver so we’ll set that up.

First, I had to install Java (the JDK, not just the JRE) on my mac.

Type java -version and then click “more info” in the alert that pops up to go to the most current java jdk mac download page.

Then, find the path to java jdk on mac by typing this into your terminal:

/usr/libexec/java_home

Then add the result as the JAVA_HOME environment variable to your ~/.bash_profile (don’t forget to restart your terminal each time after doing this). For me the actual path was:

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home"

Or alternatively, this shortcut also worked:

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

I then also needed to add:

export PATH=$PATH:$JAVA_HOME/bin

Then I installed Android Studio:

And added the path to android sdk on mac as ANDROID_HOME env variable:

export ANDROID_HOME="/Users/mlapeter/Library/Android/sdk"

On macOS, you will also need to add platform-tools to your ~/.bash_profile, by adding a line like:

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

I found the above from these android studio emulator docs. At this point you may just want to follow all the steps there to make sure you’ve got android studio setup properly. For me, at this point I’d added the following to my bash_profile:

You can then run appium-doctor --android to verify you added everything correctly. Here’s what it shows for me:

I use Expo, so at this point, I stopped and did a sanity check by starting my app with expo start and then clicking “run on android device/emulator” from the expo browser GUI that appears. It worked for me and I was able to use my app in the android emulator. If you’re not using expo you can skip this part or try running the android emulator a different way.

Running Your First Test:

I’m now at the running your first appium test step in the official docs.

First I downloaded the test apk they linked to in the docs. Then I followed their steps to create a new appium project:

mkdir appium-tests
cd appium-tests/
npm init -y
npm install webdriverio
touch index.js

To keep it simple I just dragged the downloaded test apk into that directory, then followed the docs to create the index.js file. I had to change platformVersion to 10 (and point app path to the test apk). Here’s my full index.js:

const wdio = require("webdriverio");
const assert = require("assert");
const opts = {
port: 4723,
capabilities: {
platformName: "Android",
platformVersion: "10",
deviceName: "Android Emulator",
app: "./ApiDemos-debug.apk",
appPackage: "io.appium.android.apis",
appActivity: ".view.TextFields",
automationName: "UiAutomator2"
}
};
async function main() {
const client = await wdio.remote(opts);
const field = await client.$("android.widget.EditText");
await field.setValue("Hello World!");
const value = await field.getText();
assert.equal(value, "Hello World!");
await client.deleteSession();
}
main();

Success!

iOS Setup

I’ll cover appium iOS setup in a separate post.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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