Built.io joins Software AG! Read all about the news.

Built.io Blog

Mobile Safari Test Automation with Appium


Before we delve into the details of automating testing in Safari, it’s important to remember the fundamental difference between a (native) mobile applications, a mobile web application, and a hybrid mobile application:

Native mobile apps run directly on the mobile device’s operating system. Mobile web apps are accessed using a mobile browser. Hybrid apps have a wrapper around a "webview" – a native control that enables interaction with web content.

Safari Challenges

Like Chrome, Safari is based on the WebKit rendering engine and comes with WebInspector pre-installed. It does not offer extensive browser automation but it is important for us to identify issues such as Language-level Consistency, Safari Crashes, etc. One potential issue we have seen is providing a uniform experience across multiple versions of an operating system on various devices. The app must be verified for all of the different environments that it will be deployed on to ensure uniformity.

Apple has been upgrading WebKit, an open source browser engine, to speed up Safari’s JavaScript processing in the OS X versions.

To set up test automation WebKit for Safari, follow these instructions:


  • Have the ios-webkit-debug-proxy installed.
     brew install ios-webkit-debug-proxy
  • Running and listening on port 27753, open the terminal and run the following command:
     ios-webkit-debug-proxy -c <device-id>: 27753
  • Turn on the web inspector on your iOS device (settings > safari > advanced – only for iOS 6.0 and up).
  • Create a provisioning profile that can be used to deploy the SafariLauncher App.

Install Tools and Configure

Perform the following steps in the terminal:

  • Install Appium from git:
     $ git clone https://github.com/appium/appium.git
     $ cd appium
  • Don't define any parameters and it will set the code signing identity to 'iPhone Developer'.
     $ ./reset.sh --ios --real-safari
  • Define both the code signing identity and profile identity code.
     $ ./reset.sh --ios --real-safari --code-sign '<code signing idendity>' --profile '<retrieved profile identity code>'
  • Once successfully configured and when the Safari launcher is built, start the server.
     $ node /lib/server/main.js -U <UDID>

Testing iOS Hybrid Apps on Real Devices using node.js

First, ensure that developer mode is active in your Safari preferences so that the remote debugger port may open. From here, we can perform a normal WebDriver test, and use Appium as the Selenium server with a special set of desired capabilities.


Start by using:

exports.mycapabilities = {
 browserName: '',
 'appium-version': '1.3',
 platformName: 'iOS',
 platformVersion: '8.1.1',
 deviceName: 'mydevice'

Then, use desired capabilities like these to run your test:

var serverConfig = servers.local; //local server
var driver = require(“wd”).promiseChainRemote(serverConfig); 
var desired = _.clone(mycapabilities);
desired.browserName = 'safari';

Inspecting elements and switching to WebView

Launch the Safari Browser (develop menu > inspectable devices).

// assuming we have an initialized `driver` object for an app 
driver.contexts().then(function(contexts) {
            // get list of available views. Returns array:["NATIVE_APP","WEBVIEW_1"]
            return driver.context(contexts[1]); // choose the webview context
        // do some web testing
        .context('NATIVE_APP') // leave webview context
        // do more native stuff here if we want
        .quit() // stop webdrivage

Appium will assume that any command generated within this session is intended for automating information for the web view, rather than the native portion of the app. For example, if you run getElementsByTagName, it will operate on the DOM of the web view, rather than return UIAElements.

Using Appium and node.js in this step-by-step process in conjunction with other basic concepts, you will be able to automate mobile Safari.

Like what you read? Join our community to get more technical information, chances to win prizes, and more: built.io/community

Popular Posts

Subscribe to our blog