Concepts

The magic which makes UI Testing work on iOS devices

Appium

Appium is an open source test automation framework for use with apps. You can use Appium to automate iOS apps on real, physical iOS devices such as iPhones, iPods and iPads.

Appium implements the WebDriver protocol for native apps. This protocol defines a standard way for querying which elements (such as buttons or text boxes) are displayed on the screen and to interact with these elements.

Appium runs as a HTTP server on a PC. You write scripts which communicate with this HTTP server to write test automation scripts. Appium uses a plug-in architecture and has multiple drivers. Each Appium driver is a specialized piece of code, which provides specific test automation capabilities. For example, there’s a driver for automating Safari on iOS and another driver for automating native applications on iOS devices.

graph LR; driver --> application subgraph Mac script --> Appium Appium --> driver end subgraph Device["iOS Device"] application end

Xcode UI Testing

appium-xcuitest-driver is the Appium driver for automating native iOS applications on current versions of iOS. appium-xcuitest-driver uses the Xcode UI Test framework (xcuitest) to automate UI testing on iOS devices.

xcuitest is part of Xcode. Xcode provides a general-purpose testing framework, XCTest, which can be used to write unit tests and integration tests. xcuitest is a component of XCTest which enables UI Testing.

It interacts with the iOS operating system and allows iOS developers to write scripts which run on iOS devices and automate any part of the iOS user interface. xcuitest actually consists of two pieces: there’s an Xcode plug in so that Xcode knows how to interact with iOS devices, and a component which runs on the iOS device itself. These two components communicate with each other, typically over the USB cable you use to connect your iOS device to your PC; but they can also communicate using Wi-Fi.

On the device, xcuitest co-operates with the iOS operating system using a specific daemon: the test manager daemon (testmanagerd).

graph LR; xcuitest-pc --> xcuitest-device subgraph Mac Xcode --> XCTest XCTest --> xcuitest-pc end subgraph Device["iOS Device"] xcuitest-device --> testmanagerd testmanagerd --> iOS end

WebDriverAgent

xcuitest is a framework on its own and provide its own programming interface. It does not implement the WebDriver protocol. That’s where the WebDriverAgent comes in. Originally a Facebook-sponsored project, WebDriverAgent is now maintained by the Appium community. It leverages xcuitest, but understands the WebDriver-syntax used by Appium and converts Appium queries and commands to their xcuitest equivalent.

WebDriverAgent is an application written in Objective C and runs on iOS devices. You’ll need to install WebDriverAgent on your iOS device when you want to run Appium tests on iOS devices. If you use Appium, Appium automatically installs WebDriverAgent for you.

Appium uses Xcode to install and launch WebDriverAgent. It communicates directly with WebDriverAgent over the HTTP protocol. At the same time, Xcode keeps running in the background to keep WebDriverAgent active on the iOS device.

graph LR; appium-xcuitest-driver --> WebDriverAgent xcuitest-pc --> xcuitest-device subgraph Mac appium-xcuitest-driver --> Xcode Xcode --> XCTest XCTest --> xcuitest-pc end subgraph Device["iOS Device"] WebDriverAgent --> xcuitest-device xcuitest-device --> testmanagerd testmanagerd --> iOS end

xcuitrunner

Appium uses the appium-xcuitest-driver to automate the user interface of iOS devices. This driver uses Xcode to launch and install the WebDriverAgent on your iOS devices, which then leverages xcuitest to interact with the iOS operating system. Because of this dependency on Xcode, the appium-xcuitest-driver only runs on macOS.

This is where xcuitrunner comes in. It allows you to launch the WebDriverAgent on iOS devices, and does not have a dependency on Xcode. In fact, you can run xcuitrunner Windows, Linux or macOS.

graph LR; xcuitrunner --> WebDriverAgent subgraph PC xcuitrunner end subgraph Device["iOS Device"] WebDriverAgent end

You can use this to automate iOS devices using Windows or Linux. There are two ways you can leverage xcuitrunner:

  • You can communicate directly with the HTTP server which WebDriverAgent exposes. The WebDriverAgent implements the WebDriver protocol, so you can use standard WebDriver client libraries to interact with the WebDriverAgent and automate iOS devices. In most cases, appium-xcuitest-driver directly forwards requests to WebDriverAgent. However, some functions may be implemented by the appium-xcuitest-driver and are not available when you interface directly with the WebDriverAgent.
  • You can use vanilla Appium on a Linux machine. xcuitrunner has an Xcode compatibility layer, which allows Appium to interface with it in the same way as it would with Xcode.

usbmuxd

How apps communicate with iOS devices

Code Signing

Getting iOS Applications to run on iOS devices

Last modified October 30, 2019: Add Mermaid integration (83ee7b5)