How to launch system apps in an iOS Xcode UI test case

Xcode 9

Here's the solution using Xcode 9

let messageApp = XCUIApplication(bundleIdentifier: "com.apple.MobileSMS")
messageApp.activate()

You can find a list of bundle identifier for the system apps in this post

Xcode 8

For Xcode 8 it's a little bit more complicated In order to launch an application from the Springboard you need to import the following headers

https://github.com/facebook/WebDriverAgent/blob/master/PrivateHeaders/XCTest/XCUIElement.h https://github.com/facebook/WebDriverAgent/blob/master/PrivateHeaders/XCTest/XCUIApplication.h

Then use the following (for example with Health)

Objective-C

@interface Springboard : NSObject

+ (void)launchHealth;

@end

@implementation Springboard

+ (void)launchHealth
{
    XCUIApplication *springboard = [[XCUIApplication alloc] initPrivateWithPath:nil bundleID:@"com.apple.springboard"];
    [springboard resolve];

    XCUIElement *icon = springboard.icons[@"Health"];

    if (icon.exists) {
        [icon tap];

        // To query elements in the Health app
        XCUIApplication *health = [[XCUIApplication alloc] initPrivateWithPath:nil bundleID:@"com.apple.Health"];
    }
}

@end

Swift

class Springboard {
    static let springboard = XCUIApplication(privateWithPath: nil, bundleID: "com.apple.springboard")

    class func launchHealth() {

        springboard.resolve()

        let icon = springboard.icons["Health"]
        if icon.exists {
            icon.tap()

            // To query elements in the Health app
            let health = XCUIApplication(privateWithPath: nil, bundleID: "com.apple.Health")
        }
    }
}

Swift 4

let app = XCUIApplication(bundleIdentifier: "com.apple.springboard")