Automated deeplinks testing

Automatically verify your app's deeplinks on iOS 11+ with a new XCUIApplication constructor.

UI testing under iOS 11 has the ability to interact with other installed apps. Specifically, XCUIApplication got a new constructor that takes a bundle ID. Let’s see how we use this to put our deeplinks under automated tests.


What you basically do is create a helper-app, MyHelperApp in below examples, that merely holds UIButtons for all the deeplinks your main app, MyApp, should support. For MyApp you register a URL scheme, and for HelperApp you whitelist that very same scheme under the LSApplicationQueriesSchemes key in Info.plist:

MyApp whitelisted in HelperApp

The new XCUIApplication constructor allows you to open MyHelperApp

let helperApp = XCUIApplication(bundleIdentifier: "org.merela.MyHelperApp")

…and there open a particular deeplink that MyApp supports:

let url = URL(string: "\(myAppBundleId)://\(buttonTitle)")

Finally, assert that the deeplink opened MyApp in the expected state.

With Xcode 9, check out the sample project. To try it out, first install the HelperApp and then run tests for the MyApp target. Also make sure Simulator’s ‘Hardware Keyboard’ is disabled.

CI considerations

Xcode 9 GM will be released soon, but until then you have to switch to Xcode-beta’s toolchain, to be used by xcodebuild commands further below:

sudo xcode-select -s /Applications/

This proof-of-concept script will make sure helper-app is always installed and ready to be used by main-app’s UI tests:


DESTINATION="platform=iOS Simulator,name=iPhone 7 Plus,OS=11.0"

# Build an .app for the helper-app
xcodebuild build                       \
           -destination "$DESTINATION" \
           -target $HELPER_APP         \
           -scheme $HELPER_APP         \

# Install the helper-app onto the Simulator
xcrun simctl install booted "$BUILD_DIR/$"

# UI test the main-app
xcodebuild test -scheme $MAIN_APP -destination "$DESTINATION"


One other new API worth mentioning is XCTContext.runActivity(named:block:), which logically groups subparts of each test-case, makes these groups visible in logs, and thus eases debugging:

runActivity context

There’s plenty more: performance improvements (firstMatch), screenshots, attachments, etc. - check out WWDC 2017’s What’s New in Testing.