Installation

The main driving factor in Mobile Automation is the ability to communicate and control the devices under test. A device can be physical device or virtual i.e. software simulators or emulators.

At the moment, there are 2 main mobile Operating Systems (OS) — Android and iOS. To communicate and control a device, support is needed from the mobile OS and its tooling. In practise, this means that platform tools, SDKs and dependencies have to be installed on the computer which is connected to the real devices or is running simulated/emulated virtual devices. It is possible that some of the needed dependencies requires the hosting computer to have certain support from its operating system i.e. iOS requires Mac OS and thus a Mac as a computer.

This chapter will show the steps how to install Mobile Automation support for both Android and iOS devices.

iOS

Pre-requisites

To succeed you the need following:

  • A Mac computer running macOS (Catalina) 10.15.x or later

  • An iPhone running iOS 13.x or later

During the Mac setup following software will be installed:

  • Xcode 11 or newer

  • Homebrew

  • Node.js 10.x or newer and NPM

  • Carthage

  • Additional development tools:

    • libimobiledevice

    • ios-deploy

    • ideviceinstaller

  • Appium 1.17.x or newer, WebDriverAgent and AppiumStudio

Xcode

  1. Go to AppStore and search for Xcode

  2. Install (or update) Xcode and wait for the installation to complete before continuing

Homebrew

  1. Open a terminal window and run below command:

$ /usr/bin/ruby -e "$(curl -fsSL \
  https://raw.githubusercontent.com/Homebrew/install/master/install)"
Homebrew installation

Node.js and NPM

New installation

  1. Open a terminal window and type: brew update

  2. Type: brew install node

  3. Wait for installation to complete

  4. Check installation by running:

$ node -v
v.10.16.3
$ npm -v
v.6.9.0

Update existing installation

If your existing installation has older version than 10.x, then you need to update it.

If you have not used Homebrew to install then you must find out how to upgrade that installation
  1. Open a terminal window and type: brew update

  2. Type: brew upgrade node

  3. Check the upgraded versions:

$ node -v
v.10.16.3
$ npm -v
v.6.9.0

Install webpack

  1. Open a terminal window and type:

npm install -g webpack

Carthage

  1. Open a terminal window and type:

brew update
brew install carthage
If you have previously installed the binary version of Carthage, you should delete /Library/Frameworks/CarthageKit.framework)

Additional Development Tools

Install libimobiledevice

This is a library to communicate with iOS device natively.

  1. Open a terminal window and type: brew install libimobiledevice --HEAD

  2. Check installation by running:

$ brew info libimobiledevice

Install ios-deploy

This tool is used to debug and deploy apps to connected device from command line without using Xcode.

  1. Open a terminal window and type: brew install ios-deploy

  2. Check installation by running:

$ ios-deploy -V
1.9.4

Install ideviceinstaller

This tool helps to install, uninstall, upgrade, archive, restore and enumerate installed or archived apps. The tool is needed to run tests on real devices.

  1. Open a terminal window and type: sudo xcode-select -r

  2. Install by typing: brew install ideviceinstaller

  3. Check installation by running (you should see the usage listing):

$ ideviceinstaller

You can use ideviceinstaller to check right bundle ID’s from installed apps easily:

$ ideviceinstaller -u <UDID> -l
You can list all available UDIDs by executing command instruments -s devices
if you get an device lockdown error, then you might have to re-install libimobiledevice and ideviceinstaller:
$ brew uninstall ideviceinstaller
$ brew uninstall libimobiledevice
$ brew install --HEAD libimobiledevice
$ brew link --overwrite libimobiledevice
$ brew install --HEAD  ideviceinstaller
$ brew link --overwrite ideviceinstaller
$ sudo chmod -R 777 /var/db/lockdown/

Optional: install ios_webkit_debug_proxy

For accessing web views on real iOS device Appium uses ios_webkit_debug_proxy. To install it follow the instructions in iOS WebKit Debug Proxy web page.

Appium framework

This section instructs how to install needed software for test automation using Appium. The required Appium version is 1.17.x or newer.

Appium

  1. Open a terminal window and type: npm install -g appium

  2. Check the version:

$ appium -v
1.17.0

WebDriverAgent

  1. Open a terminal window and type: cd /usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent

  2. Fetch all needed dependencies by typing:

$ ./Scripts/bootstrap.sh

Optional: AppiumStudio

AppiumStudio can be used to visually inspect various information about the UI elements of a phone application and/or follow test execution on Mac screen. AppiumStudio is free to download, but it requires to fill-up contact form.

  1. Download and install AppiumStudio

  2. Before launching AppiumStudio for the first time, close Appium server if running

  3. Launch AppiumStudio

  4. Click Open File >> Agent Properties…

  5. Configure execution port to some other value than the default 4723 which is used by Appium server. Change the value e.g. to 4724. This change allows AppiumStudio and Appium server to run at the same time.

  6. Connect target device (iPhone) to the Mac using the cable

  7. To add the connected device, click Device >> Add Device… >> iOS Device and fill-in required information and click OK

  8. At some point AppiumStudio asks permission to use Accessibility Controls in the system. Allow that in the system preferences of the Mac.

  9. Connect to the device by selecting Device >> Open Device

  10. After a while iPhone’s screen should be visible on Mac’s window

if you would like to inspect the elements on the device’s screen, click Object Spy icon from the bottom of the window showing the screen

Device Setup

In order to succeed, you need a Mac setup according to above instructions, an iPhone and Apple Developer account. Apple Developer account is needed for WebDriverAgent building and package signing as well as for your own applications. You need to register your Mac and iPhone to that account in order to use it in test automation. WebDriverAgent is a WebDriver server implementation for iOS that can be used to remote control iOS devices.

Register Mac and iPhone to Developer Account

  1. Connect iPhone to your Mac using the cable

  2. Go to website: https://developer.apple.com/

  3. Click Account at the top of right corner

  4. Login with your credentials

  5. Click Certificates, IDs & Profiles

  6. Click Devices

  7. Click ‘+’ to register a new device

  8. Select iOS, tvOS,watchOS as platform for iPhone and Mac for your computer

  9. Give a name for the device

  10. Copy & paste device UDID to Device ID field e.g. from iTunes’ device setting summary page (click Serial Number to switch between values)

  11. Next, press continue to register the device

  12. Now, you should see the device in the list

You will need the device ID (UDID) also when configuring the automated tests or if building WebDriverAgentRunner from command line

Signing in Developer Account with Xcode

  1. Open Xcode

  2. Select Xcode >> Preferences… >> Accounts

  3. Click the ‘+’ sign and choose Apple ID as account type and login

WebDriverAgent configuration

This configuration will have to be done each time when a new version of Appium is installed — or when WebDriverAgent is updated:

  1. Open a terminal and change working directory to:

    $ cd /usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent
  2. Open Xcode project file by typing:

    $ open WebDriverAgent.xcodeproj
  3. For both, the WebDriverAgentLib and WebDriverAgentRunner targets, select "Automatically manage signing" in the "Signing and Capabilities" tab, and then select your Development Team. This should also auto select Signing Certificate.

  4. Check, and possibly change, Bundle Identifiers to be different for WebDriverAgentLib and WebDriverAgentRunner. You can change it under “Build Settings” tab and “Packaging” section.

  5. Next, select WebDriverAgentRunner as active schema and target it to your connected iPhone

  6. Hit the “Play” button to build the project

  7. If all went fine, you should see “Build Succeeded” notification on the screen

Optionally, steps 5 and 6 can be done in terminal. You need device UDID to do this. In the WebDriverAgent directory (see step 1) run:

$ xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id=<UDID>’
...
** BUILD SUCCEEDED**