Introduction
Appium is a tool for automating apps. It has two components: the Appium server, which does the actual automating, and a set of Appium clients, one for every popular programming language. You write tests in your favorite language by importing the Appium client for that language and using its API to define a set of test steps. When you run the script, those steps are sent one-by-one to a running Appium server, which interprets them, performs the automation, and sends back a result if appropriate.
Appium was initially developed to automate mobile applications, first iOS and then Android. In recent years Appium has gone beyond mobile to support Desktop or even TV apps. This guide focuses on mobile testing
for iOS and Android.
There are several kinds of mobile apps, and Appium lets you automate all of them:
Native apps — apps built using the native mobile SDKs and APIs
Web apps — websites accessed using a mobile browser
Hybrid apps — apps with a native container and one or more webviews embedded in that container.
Appium Setup
Getting going with Appium itself is fairly straightforward. However, Appium depends on the various mobile SDKs and system dependencies in order to perform its magic. This means that even if you’re not an app developer yourself, and don’t plan on writing iOS or Android code, you’ll need to get your system set up as if you were. Don’t worry—this guide will walk you through it. I should point out for our Windows and Linux friends that this
guide assumes a Mac environment, since iOS testing can only be done on a Mac. If you’re only interested in Android testing and want to run Appium on Windows or Linux, refer to the Appium documentation for setup
information specific to your host OS.
IOS-SPECIFIC SYSTEM SETUP
Install Xcode
Install Xcode’s CLI tools (you’ll be prompted the first time you open a fresh version of Xcode)
Install Homebrew
Install Carthage via Homebrew: brew install carthage
ANDROID-SPECIFIC SYSTEM SETUP
Install Android Studio and SDK Tools
Using the Android Studio SDK Manager, download the latest Android SDK, build tools, and emulator images
Install the Java Development Kit (JDK)
In your shell login file (~/.bashrc, etc…),
Export $ANDROID_HOME to the location of the Android SDK on disk. If you didn’t set this manually, it’s probably at the default location
Export $JAVA_HOME to the Contents/Home directory inside of the newly installed JDK
Configure an Android Virtual Device (AVD) in Android Studio.
Appium setup
There are two ways to install officially released versions of Appium: either from the command line via NPM or by installing Appium Desktop.
Appium From the Command Line
Appium is shipped as a Node.js package, so if you have Node.js and NPM installed on your system, you can simply run:
npm install -g appium
And the most recent version of Appium will be installed. You can then run Appium simply by typing appium from the command line.
Appium From Appium Desktop
There is a very nice graphical front-end for Appium, maintained by the Appium Developers, called Appium Desktop. It bundles Appium along with a useful app inspector tool, so you can simply download Appium Desktop without worrying about any other system dependencies.
Once you’ve got it on your system and opened up, you should be greeted with a screen like this:
Now you can simply hit the “Start Server” button, and you’ll see an Appium log window open up:
When we eventually begin running tests, this is where you’ll see the output of what Appium is doing. Reading the Appium server logs can be a very useful way to understand what is happening under the hood! But for now, we just want to make sure that everything is working. You can go ahead and stop the server if you want, or leave it running for later.
AN APPIUM CHECKUP
Once you’ve got Appium going, it’s worthwhile to make sure your system is configured correctly before trying to run tests. There’s a handy little tool called Appium Doctor that will do this for you:
npm install -g appium-doctor
appium-doctor
Running the appium-doctor command will output how well-configured Appium believes your system to be for the various platforms. If anything looks amiss, revisit the instructions above or seek help.
JAVA CLIENT SETUP
There is one Java package that we’ll be using in this guide, hosted at Maven Central: io.appium/java-client. It contains a number of features, but primarily it’s what we’ll be using to speak the WebDriver protocol with the Appium server.
We’ll configure instructions for downloading and using the Java Client in the next section as part of our project setup, using Gradle.
PROJECT SETUP
For the rest of this guide we’re going to be working on a Java project, starting from scratch. To get set up for the project, identify a path somewhere on your system that will be used for the project. It doesn’t matter where it is. But in this guide, we’re going to pretend it is /path/to/project, so anytime you see that path, just replace it with the one you’re using. Next, initialize a new Java project in that directory, using Gradle as the build and dependency management tool. I’m using IntelliJ IDEA as my Java IDE while developing this guide, but
it shouldn’t matter which IDE you choose. (In general won’t be spelling out instructions specific to the IDE, so find yourself a good guide to your IDE if you’re new to it, for example setting up a Gradle project in IDEA). Give the
project a group ID and artifact ID of your choosing (I will use io.appium and bootcamp, respectively). At this point you should have a brand new Java project in /path/to/project, with some Gradle-related files (the gradlew wrapper, for example), and the typical Java file structure for our code (src/main/java, etc.)
Now, download a copy (one for each platform) of the test app we will use for this project. The app is called, drumroll please, The App and it’s a silly little thing that will help us get going with automation. There’s a version for both iOS and Android. Download each app from the v1.2.1 release page on GitHub.
Put them in the src/test/resources directory (since we’ll be using test as the place to put our test code, of course). At this point your project directory should look roughly like:
Next, we need to set up our project dependencies. Open up build.gradle and make sure the dependencies section looks like:
In other words, we’re adding JUnit, the Appium Client, and Hamcrest (an assertion library) to our project, at the specified versions. Once you save the build.gradle file, you’ll need to refresh the Gradle project (your IDE should
helpfully suggest an easy way to do this).
Comments