Appium Setup — iOS and Android

Lana Begunova
22 min readNov 7, 2023

--

How to Setup Appium for Mobile Test Automation

Appium targets mobile platforms, and hence its setup requires a mobile development and test environment. Let’s check out these requirements and dive into details to learn about how to configure both iOS and Android, as well as the Appium server.

General Requirements

General requirements for each platform : Node.js, NPM, Appium Client.

Let’s figure out how to get Appium set up locally for both iOS and Android automation. Before we get started, let’s review the general requirements for each platform, so that we know what we’re actually installing, and why.

① Node.js

For automation of both platforms, and regardless of whether we are running macOS or Windows, the main dependency for the Appium server is a programming language runtime called Node.js. Node.js is basically like the Python command line tool — it’s a program that lets us execute scripts on our computer. Node.js has a .js in its name, because it is a platform for running Javascript (JS) code. JS is a programming language that was originally developed to run inside of a web browser, but it has proven to be a popular enough language that people wanted to run it on their servers as well, not just in the browser. Node.js is the most popular way of running JS code outside of the browser.

What do we need Node.js for? Well, Appium is itself written to target the Node.js platform. So just like we need , e.g., the Python programming language interpreter on our computer in order to run the Python test code, we also need Node.js on our computers in order to run Appium.

② NPM

Node.js and Python are similar in many ways, including the use of 3rd-party packages or modules. When we are working with Python, we use a tool called pip to install Python packages from the web and make them available in our environment. When we are working with Node.js, we use a tool called npm for the same purpose. We need Node.js and NPM on our machine in order to download and run the Appium server.

③ Appium Client (Language Bindings)

In addition to the Appium server, we need an Appium client of some sort. We focus on Python in this post, so we need the Python interpreter. We’ll also need the Appium Python client, which we can download via pip.

pip install Appium-Python-Client
https://github.com/appium/python-client#getting-the-appium-python-client

iOS

iOS requirements: Mac, Xcode, Carthage

① macOS

Now let’s discuss what’s required for Appium iOS automation. For iOS automation, we first of all need a macOS computer to connect to devices and host the Appium server. This means that, unfortunately, running iOS tests on Windows is not supported. We can write and run test scripts themselves on Windows, as long as they connect to an Appium server running on a Mac.

② Xcode

The main software requirement for iOS is the Xcode development environment. Xcode is a whole suite of development tools that Apple provides, mainly for the purpose of writing iOS, tvOS, and macOS apps. The way that Appium kicks off iOS tests relies on tools that come bundled with Xcode, so Xcode is a requirement. We don’t actually need to use Xcode ourselves as part of writing and running Appium tests — it just needs to be on our system and to have its additional command line tools downloaded and available.

③ Carthage

Our next requirement is called Carthage. Carthage is a software package manager, much like pip or npm. Carthage is specifically designed for Cocoa applications, which is to say, applications developed for macOS, iOS, tvOS, etc. Appium uses Carthage as part of the XCUITest driver, which is written as a Cocoa app so that it can run on iOS. We don’t need to concern ourselves about or use Carthage directly — it just needs to be on our system so that the XCUITest driver can use it under the hood in order to build its own components the first time it runs.

Android

Android requirements: Java JDK, Android Studio, SDK with build tools and virtual devices.

What about Android? What do we need to get that running? Android automation and setup can take place on macOS, Windows, or Linux. Regardless of the platform we run Appium on, the Android automation requirements are the same.

① Java

The first requirement is the Java JDK, which we’ve already learned how to set up in a this demo.

② Android Studio

The second requirement is something called Android Studio, which is sort of like Xcode, but specifically for the purpose of developing Android apps. It’s a whole development environment that lets us write and compile code in Java (or another language used for Android development called Kotlin). It has a lot of special features that help us with the visual design of Android apps, for example. Android Studio comes with a management system for versions of Android, and for Android virtual devices.

③ SDK, Build Tools, Virtual Device

The third requirement is basically that we use this management system to actually install the tools and system images that go with the particular version of Android that we want. For example, if we want to run tests on Android 10, we’ll need to make sure we have the Android 10 SDK, build tools, and virtual device.

iOS Setup — Practical Walkthrough

It’s time to do some practical steps to make sure our setup is going to work for iOS.

macOS/Xcode

The first step is to make sure you have Xcode. We may already have it if we’ve done certain kinds of software development on our Mac in the past. We can check in the Applications folder and launch it if so. But the way to get it is to open up the App Store, search for Xcode, and then update or install it.

Open the App Store, search for Xcode, and then update or install it.

It’s quite large, so it can take a significant amount of time to download. Feel free to take a break and have some coffee ☕️.

Okay, now that we have Xcode, the next thing to do is open it up. When we launch it, and the first time we run it, we get greeted with a dialogue saying some additional components need to be downloaded. Go ahead and do this if needed.

At this point, you should be set up. But it’s better to verify that Xcode’s command line tools have been installed. To do this, open up a terminal, and run the command:

xcode-select --install

This runs a special Xcode program that will download additional command line tools that are required. We might get a popup that says they’re already installed, and if so, great. Otherwise, allow the installation to continue.

Now, let’s open up Xcode and check what version of the iOS SDK (Software Development Kit) it comes with. The iOS SDK is basically the set of software libraries that are required to build iOS apps. To automate a particular version of iOS, e.g., iOS 17, we need to have the iOS SDK for that version downloaded from within Xcode. Each version of Xcode comes with the most recent version of the iOS SDK by default, so we may not need to download additional versions unless we want to test on something else.

One way of checking which version of SDK we have installed is to open up the Devices and Simulators window. We can do this by going up to the Window menu, then opening Devices and Simulators. Click the Simulators tab, and we should see a list of iOS simulators that have been installed. Let’s click on any one of these, e.g., iPhone 15, and in its details we will see which version of iOS it’s designed to run on. Take a note of this version, because we might need this version later.

Lastly for this Xcode setup, let’s actually open up an iOS simulator to make sure it works. What is an iOS simulator? A simulator is basically a virtual iOS device that runs on our macOS machine. It’s not exactly the same as a real iOS device, and it doesn’t have all the same low-level hardware stuff going on under the hood, as a real device would. But it is a way to run and test apps that we’re building without needing a physical iOS device, so it’s certainly useful.

To open the simulator, we can go up to the Xcode menu, then to Open Developer Tool, then Simulator. One should start to open up immediately. It might be any kind of simulator. In our demo case, it’s an iPhone 15. We can change the kind of simulator that’s booted/loaded by going up to the File menu of the Simulator app, then to Open Simulator, then to the iOS SDK version we want to open a simulator for, and then finally selecting an appropriate form factor.

To open the simulator, we can go up to the Xcode menu, then to Open Developer Tool, then Simulator.
A simulator should start to open up immediately.
It might be any kind of simulator. In our case, it’s an iPhone 15.
We can change the kind of simulator that’s booted/loaded by going up to the File menu of the Simulator app, then to Open Simulator, then to the iOS SDK version we want to open a simulator for, and then finally selecting an appropriate form factor.
In our demo, we’ve switched to an iPhone 13.

Carthage and Homebew

Now we’re ready for the last step of iOS setup, which is installing Carthage, the dependency manager that is used by Appium’s XCUITest driver. The easiest way to install Carthage is to use yet another package manager. Unfortunately, we have to use a bunch of different technologies to get everything going . This new package manager is not for a programming language at all. It’s actually for the macOS system itself. There are lots of convenient command line utilities out there, and it’s nice to have one consistent way of downloading and installing them on our machine. Let’s use a tool called Homebrew.

We can set up Homebrew by heading over to https://brew.sh, and copying the installation command we find there.

We can then paste it into a terminal and run it, and Homebrew will be installed. It may prompt us for a Password.

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> Checking for `sudo` access (which may request your password)...
Password:🔑

Now that we have Homebrew installed, we can use it to install Carthage by running the command:

brew install carthage

This might take a few minutes. Once it completes, we are good to go with all the iOS setup required for Appium.

Android Setup — Practical Walkthrough

Now let’s move on to Android setup. First, we need to get Android Studio. To do this, we can go to https://developer.android.com/studio. We click the download link for our platform, and run the installer as we normally would, in order to install it as a new app.

Once it’s installed, go ahead and open it up.

We’ll be greeted with a splash screen that has a More Actions menu at the top right.

More Actions menu.

When we open up this menu , notice that the bottom two options are called SDK Manager and Virtual Device Manager.

More Actions menu item — SDK Manager.
More Actions menu item — Virtual Device Manager.

Virtual Device Manager is how we create and run Android virtual devices, otherwise known as emulators. Android emulators are very similar in concept to iOS simulators, though they differ in a lot of technical details. Android emulators actually implement an entire virtual device down to the hardware, so even though they run on our computer as a virtual device, they are using all the same system code as would run on an actual physical device.

We also have the SDK Manager here. SDK stands for “software development kit” and it just means a collection of tools for building software. Let’s first navigate into the SDK Manager.

Opening up this menu item launches the preferences for Android Studio and takes us to the SDK Manager within them. The first thing to notice is the text field labeled Android SDK Location.

/Users/lanabegunova/Library/Android/sdk

The text in this box is a path to the location of the Android SDK on our disk. This is an important path for Appium, because Appium works with the Android SDK and so it needs to know where it is located on our system. Take a moment to write down or copy this path somewhere else, because we’ll need it shortly. The exact path may vary depending on the system.

In our SDK Manager, there are also three tabs here: SDK Platforms, SDK Tools, and SDK Update Sites. Let’s first go to SDK Platforms.

This is a list of Android versions which we can download the SDK for. Basically, we need to download any of these versions that you want to run Appium tests for. For now, just make sure the latest stable version is installed. If there’s no checkbox by it, check it. We’ll eventually hit “OK” to install all the new software, but we can wait on that part for a moment.

Now, let’s go to SDK tools. Here there are four tools we need to make sure are checked:

  • Android SDK Build-Tools
  • Android Emulator
  • Android SDK Platform-Tools
  • Intel x86 Emulator Accelerator
Make sure to select/check 4 tools: 1) Android SDK Build-Tools, 2) Android Emulator, 3) Android SDK Platform-Tools, and 4) Intel x86 Emulator Accelerator (HAXM Installer).

So we select all of these and hit “OK” to go through the download process. We’ll need to accept various license agreements and so on to make this all work.

As part of the install, if we’re getting the Intel x86 Emulator Accelerator for the first time, it will open up its own installer. Please go through this process. We can keep all the default options that are recommended during install.

Note that if we are on macOS it’s an expected outcome that the Intel x86 Emulator Accelerator install fails the first time we run it. Do not get alarmed if that happens.

Intel x86 Emulator Accelerator (HAXM Installer)

What is the Intel x86 Emulator Accelerator, otherwise known as HAXM? It’s an extension for our computer that enables Android emulators to run much faster than they otherwise would, which is really important.

One note for those running macOS: at the end of installing HAXM, you might have gotten a message that a kernel extension was blocked from loading. The system extension blocked message looks something like this.

Error message for a blocked system kernel extension.

If this error is that we got, then we need to open up our System Settings.

Open System Settings.

Then head to the Privacy and Security preference pane which looks like this image here.

Head to the Privacy and Security preference pane.

Down at the bottom we should see a message that says something from Intel Corporation was blocked from loading.

We can now click “Allow” to enable the extension.

At this point, because it was blocked from installing. We might need to actually run the installer again for it to complete installation successfully. And now, again, if we are on macOS, it’s advisable to open up a terminal to check if the HAXM extension is actually running. So let’s open one up and run this command:

kextstat | grep intel

What this command does is list out all the kernel extensions that are currently installed on the system. We do that using the special kextstat
(kernel extension status) command. Then we filter that list for any lines that contain the string 'intel', which is highlighted in red in the single line output that we received.

If you’ve never seen the pipe | character in a command before, what it does is redirect the output of one command into the input of another command. So we are running thekextstat command, and directing its output into another command called grep intel. grep is a command that allows filtering its input by some keyword that we care about (in this case intel). This is what filters the output kextstat to only the lines that contain intel.

If we see anything show up after running this command, it means HAXM is loaded. If we don’t see anything show up, it means HAXM is not running. If this is the case, we might want to try restarting our computer and/or re-downloading and re-installing HAXM directly from the Intel’s website. Sometimes messing with kernel extensions, as we’ve done, requires restarting the computer.

Alright, now that HAXM is set up, let’s configure an Android Virtual Device, or an emulator. To do that, we go back to Android Studio, and click the Virtual Device Manager menu item from the More Actions menu.

More Actions menu.
More Actions menu item — Virtual Device Manager.

When the Virtual Device Manager loads up, you probably won’t have devices listed here. Instead you’ll have a big button that says Create Virtual Device.

If you have any virtual devices listed, like I do, you can create a device by clicking the Create Device button.

Create a device by clicking the Create Device button in the top left corner.

Here, let’s click Create Devicein the top left corner to start creating our first device. Now, we can essentially walk through the wizard which enables us to create a new virtual device, based on any kind of hardware profile that we want.

Walk though the Virtual Device Configuration wizard. Create an emulator based on a particular hardware profile we want.

We can choose to walk through this wizard with all of the default options, but make sure that for the system image, you choose the latest official release. At the time of writing this story, it is Android U (UpsideDownCake) or API level 34.

Choose the system image based on the latest official release. At the time of writing this story, access to version U (UpsideDownCake) is available.
API level for UpsideDownCake system image is 34.

If the official release is not available to you, there’s a download link ⬇️ next to it. Make sure to click that download link to download the system image so that you can create an emulator using that image. Then come back to this wizard to choose the correct image.

Click the download link ⬇️ next to the desired system image.
For example, download the system Image for the API_34 release.

Finally, we can hit Next and give the emulator a name of “test”, “appium”, or anything else that will help us remember what it’s for.

Click Next, once the desired release image is downloaded.

Now we click Finish to close the wizard and create our virtual device.

Click Finish.

Once it’s created, it will show up in the list of virtual devices, with some action buttons on the right side. In our case we already have one created.

Once our emulator is present in the device list, to run it we go to the Actions column and click the play ▶️ button.

Once our emulator is present in the device list, to run it we go to the Actions column and click the play ▶️ button.

Initial launch of a new emulator may take a few minutes.

It will take several minutes, but we should eventually see an Android virtual device go through its startup routine. Now, explore it and notice how it behaves just like a real Android device in pretty much every way.

Explore the launched emulator. It behaves like a real Android device almost every way.

There’s one last thing we need to do to get our Android setup fully functional, and that is to set up the appropriate environment variables so that Appium knows where the Android SDK is installed. Do you remember that path that we had to save a bit earlier? Now’s the time to use it. If you lost track of it, you can always open up the SDK Manager, and look again at the path displayed near the top of that window.

Android SDK Location path — /Users/lanabegunova/Library/Android/sdk — needed to set up the ANDROID_HOME environment variable.

What we want to do is set this path as the value of the ANDROID_HOME environment variable.

Please refer to the story on environment variables, if you require help on making this happen. Basically, it looks like adding an export command to our shell startup script on macOS. Let’s do this now in the .zshrc file.

ANDROID_HOME is the name of the variable we want to define. We need to set it to the path that we found in Android Studio’s SDK Manager. In my case it’s /Users/lanabegunova/Library/Android/sdk. Yours might be different.

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

ANDROID_HOME is the name of the variable we want to define. And we need to set it to the path that we found in our Android Studio’s SDK Manager, which is /Users/lanabegunova/Library/Android/sdk or ~/Library/Android/sdk.Save that edited .zshrc file. If we are on Catalina macOS or lower, it’s customary to deal with a .bashrc file instead.

And, of course, if we run on Windows, we do this by navigating through the control panel using the UI, adding an environment variable, and setting the path as the value of the ANDROID_HOME variable.

I have generally also found it useful to add several directories that are inside ANDROID_HOME to my PATH, so that I have access to Android-related commands from my terminal. Technically this is optional, but I recommend you adjust your path in the way that I’ve outlined here, to include these directories as well:

export PATH=$PATH:$JAVA_HOME/bin:/Users/lanabegunova/bin:$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin

On macOS, it looks like adding ANDROID_HOME/emulator, platform-tools, tools, and tools/bin.

SDK Manager depicts some options that correspond to ANDROID_HOME directories.

On Windows, it’s basically the same, except we need to use the percent % signs, and we might want to add each path as a separate entry in the Path list.

%JAVA_HOME%\bin;%ANDROID_HOME%\emulator;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;%ANDROID_HOME%\tools\bin

All right, that’s a wrap for Android.

Appium Setup — Practical Walkthrough

Now we are ready to install Appium itself. We’re actually going to see how to install Appium in two separate ways. You can install Appium via the Node Package Manager, as mentioned before.

The first thing we need to do is install Node.js and NPM. If you already have them, great! You can check by running the commands node or npm in a terminal, and seeing if they don't result in an error. (If you run node, it will take you into an interpreter session so you can hit CTRL+C to exit out of it). If instead you get an error, you don't have node and NPM and need to install them.

The easiest way to install Node.js on macOS is to run the command:

brew install node

This uses the Homebrew system package manager to install Node and NPM, just like we did for Carthage.

For Windows, the easiest method is to head to the Node.js website’s download page at https://nodejs.org/en/download/ and get the appropriate installer for your system.

Run that installer and then open up a command prompt.

Now, whether on macOS or Windows, we head to our terminal or command prompt. Try to run the npm command , and verify that NPM's help text is printed out as a result.

If so, Node and NPM have been installed successfully. Now, we can install Appium.

It’s recommended to use Appium 2.0 or higher, which has a different way of managing drivers than Appium 1.x. Let’s run the npm info appium dist-tags command to see what has been released on NPM at the present moment:

npm info appium dist-tags
{
latest: '2.2.1',
beta: '2.0.1',
rc: '2.0.1',
next: '2.0.1',
fake: '1.20.0-fake.0'
}

This NPM command prints out an object that tells us which versions of Appium have been released to NPM under different tags.

The most recent official release is called latest. What we’re looking for is the name of the tag which has a version of 2.x after it. If it’s latest, great! But it might be beta or next instead. Whatever it is, remember the name of that tag. Now, we can install that particular tag of Appium with this command:

npm install -g appium@tag

This NPM command installs a package from NPM. The -g text there is a command line flag to tell the NPM install process to install Appium globally, making it available for us anywhere in our terminal, and not just in the current directory. After this, we have the name of the package we're installing, which is appium, then the @ symbol, and then the word tag. But where we have the word tag here, we should run it with the actual tag, so latest, beta, next, or whichever.

This command might take a while to run, but when it finishes, Appium should be installed.

Note that if Appium was not able to be installed due to a permissions error, you might be tempted to retry the npm install command using the sudo privilege escalation tool. This is not a good idea, so if you're in this position, check the top of the transcript for a note on how to make it possible to install node modules without using sudo.

Let’s give Appium a whirl to make sure it was installed correctly by using the appium command:

appium
[Appium] Welcome to Appium v2.2.1
[Appium] Appium REST http interface listener started on http://0.0.0.0:4723
[Appium] You can provide the following URLs in your client code to connect to this server:
[Appium] http://127.0.0.1:4723/ (only accessible from the same host)
[Appium] http://10.0.0.76:4723/
[Appium] No drivers have been installed in /Users/lanabegunova/.appium. Use the "appium driver" command to install the one(s) you want to use.
[Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.

And we should see this output that says that Appium is listening, and moreover that no drivers have been installed. So now that we have Appium itself, let’s get the two drivers we care about.

The way we manage drivers using Appium is pretty easy. First of all, let’s run appium driver list. When we do that, we get a list of drivers and whether or not they are installed.

appium driver list
✔ Listing available drivers
- uiautomator2 [not installed]
- xcuitest [not installed]
- mac2 [not installed]
- espresso [not installed]
- safari [not installed]
- gecko [not installed]
- chromium [not installed]

We don’t have any yet, but we do see a list of drivers which we can install by name. So let’s go ahead and install the xcuitest driver (if we're on a Mac, that is):

appium driver install xcuitest
✔ Installing 'xcuitest' using NPM install spec 'appium-xcuitest-driver'
ℹ Driver xcuitest@5.8.1 successfully installed
- automationName: XCUITest
- platformNames: ["iOS","tvOS"]

Let’s get our Android driver as well. We’re pulling down the uiautomator2 driver, which is the one we want.

appium driver install uiautomator2
✔ Installing 'uiautomator2' using NPM install spec 'appium-uiautomator2-driver'
ℹ Driver uiautomator2@2.34.0 successfully installed
- automationName: UiAutomator2
- platformNames: ["Android"]

When the driver installation commands complete, go ahead and run appium driver list again to check that our two drivers — XCUITest for iOS and UiAutomator2 for Android — are now registered successfully.

XCUITest (iOS) and UiAutomator2 (Android) drivers are installed. Verify with command appium driver list.

With these drivers installed, that’s it for Appium server setup. That’s all the configuration we need to do that relates to Appium itself.

If you ever need to update all the installed drivers in one go, try the appium driver update installed command:

I welcome any comments and contributions to the subject. Connect with me on LinkedIn, X or GitHub.

--

--

Lana Begunova

I am a QA Automation Engineer passionate about discovering new technologies and learning from it. The processes that connect people and tech spark my curiosity.