Building a Mobile Automation Lab (Part 2) — Paving the Yellow Brick Road

Ivan Lee
Aaptiv Engineering
Published in
4 min readJan 4, 2018

Welcome back to our guide to building a mobile automation lab (on the relatively cheap)! In this post, we’ll set up Appium on the new Mac Mini’s. If you haven’t gotten a chance, check out Part I of the series for more information about our architecture and physical infrastructure.

Don’t Forget Your Brain

Scarecrow Cat reminds you to use a password manager!

First, let’s make sure we have everything we’ll need for installation and configuration!

  • You’ll need an Apple Developer admin account so you can manage your team’s certificates and provisioning profiles.
  • You’ll name computers, devices, email accounts, and device accounts. Coming up with an easy to understand naming scheme (e.g. COMPANY-DEVICE-##) to help with troubleshooting and maintenance.
  • You’ll be creating a lot of emails. It’ll save time and overhead if you can create them using a company domain.
  • You’ll be creating a lot of passwords. A password management solution that can fill in on passwords on mobile (in our case, Lastpass) is recommended!

Setting up the Mac Mini

Laying the foundation

We recommend performing the following tasks on each Mac Mini:

  • Create Apple Store account (without providing a credit card) and install all software updates.
  • Set up SSH and VNC access so you can access the Mac Mini remotely.
  • Install homebrew which is used to install Appium dependencies.
  • Install your favorite terminal replacement and shell to streamline configuration and administration.
  • Install miniconda as some Appium dependencies require Python 2.7.
  • Install & update Xcode and Android Development Studio to install latest development tools.
  • Set up a consistent folder structure for scripts, logs, and artifacts (IPAs & APKs).

This took us about an hour and a half, inclusive of thumb-twiddling while waiting for software to install.

Tips:

  • Once you’ve configured remote access, you can complete setup over SSH/VNC and reclaim your peripherals to start on the next Mac Mini.
  • A simple desktop background (e.g. from http://simpledesktops.com/ ) made it easy to identify a Mac Mini when connected via VNC.
  • We’d recommend starting up your app in a mobile emulator/simulator after installing XCode & Android Development Studio to help check that everything’s installed correctly!

Installing Appium

Appium is an open-source tool for automating native, hybrid, and mobile applications on mobile devices. It wraps platform-specific automation tools in the WebDriver interface.

The Appium website has a lot of wonderful documentation that’s organized somewhat haphazardly. We installed Appium by following the following steps:

  • Install nvm (instructions here) and install the latest LTS node version (8.9.0 at time of writing).
  • Install dependencies via homebrew.

brew install libimobiledevice

brew install carthage

brew cask install java

  • Install authorize-ios and allow access to the simulator.

npm install -g authorize-ios

sudo authorize-ios

  • Add ANDROID_HOME to your environment and point to the Android SDK install directory (e.g. [home]/Library/Android/sdk).
  • Add JAVA_HOME to your environment and point to the Java home.

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

  • Install Appium and Node dependencies.

npm install ios-deploy

npm install appium-doctor

npm install appium

  • Run appium-doctor and resolve any issues.
  • Run appium!

You should see something like the following in the log:

[Appium] Welcome to Appium v1.7.1

[Appium] Appium REST http interface listener started on 0.0.0.0:4723

Operationalizing Appium

Woohoo! We’ve got Appium up and running — it’s certainly been a journey to get here. Now we want to make sure we can keep it running over the next weeks (or months!).

Tip: Source control your script! This avoids any heartbreaks from hardware failures or human error.

Running Appium

We found it helpful to write a simple shell script to start up Appium. Piping standard output and standard input to log files keeps the server up and running if anything fails!

#!/usr/bin/env bash

set -o errexit

set -o pipefail

set -o nounset

# set -o xtrace

# Set magic variables for current dir

__dir=”$(cd “$(dirname “${BASH_SOURCE[0]}”)” && pwd)”

# Set app variables

LOGFILE=”$__dir/appium.log”

ERRORLOGFILE=”$__dir/appium_error.log”

appium >> $LOGFILE 2> $ERRORLOGFILE &

Log Rotation

Appium is a decently verbose application. We don’t want our test automation to fail because we ran out of disk space! We used lightweight BASH log rotation script (here’s a few examples) to roll, archive, and (eventually) delete old files.

Monitoring Appium

Appium is, all things considered, a pretty stable application! When it has problems, it generally crashes entirely (versus becoming unresponsive). We use DataDog’s OSX client and process checks to alert us if an Appium instance crashes.

You can also combine the status endpoint with Zabbix, Nagios, or just a cron’d shell script for more detailed monitoring!

➜ ~ curl http://localhost:4723/wd/hub/status

{“status”:0,”value”:{“build”:{“version”:”1.7.1",”revision”:null}},”sessionId”:null}

Maintenance via SSH/VNC

Inevitably you’ll need to do some kind of maintenance on your Mac Minis. Systems need restarting, Appium needs upgrading, Apple releases a new OS, et cetera. In these cases, we found that setting ourselves up for effective remote maintenance helped a lot.

  • We use VNC Viewer for remote desktop access. We also keep a flat-screen monitor nearby in case we need to directly access the machine (e.g. if you’re using wireless and the network drops).
  • We use a iTerm2’s split panes to view Appium logs on our nodes. Setting up some aliases helps too!

Final thoughts

Whew! You made it through a lot. With false-starts and lessons-learned, we spent two to three days to set up our four Appium nodes (inclusive of troubleshooting, mad Googling, and coffee breaks).

Post-setup, our mobile automation lab’s been very stable with major outages only during major desktop or mobile OS updates (for example iOS 10 to iOS 11).

In Part 3, we’ll cover virtual and physical device setup and provisioning. Provisioning profiles, certificates, and troubleshooting oh my!

--

--

Ivan Lee
Aaptiv Engineering

Quality Engineering Professional, Occasional Hamster