XCUIApplication

public extension XCUIApplication

XCUIApplication extension contains additional properties and methods which detect currently running target like iOS device, iOS Simulator, iPad or iPhone.

deviceType uses screen size to guess device that tests are running on. May be useful if there is some device specific behaviour that has to be checked. Note that XCUIApplication already has verticalSizeClass and horizontalSizeClass that can be used to distinguish between different layouts from interface designer.

Example:

if app.deviceType == .iPhone35 {
    let button = app.buttons["more"]
    button.tap()
}

In addition to deviceType, the actualDeviceType can return device type depending on device identifier. Bigger phones may have zoom mode enabled. In that case reported screen size will be smaller.

Example:

if app.actualDeviceType == .iPhone47 && app.deviceType == .iPhone40 {
    print("Detected iPhone 6 in zoom mode")
}

Extension contains set of helper properties around deviceType which returns Bool value:

  • isRunningOnIpad
  • isRunningOnIphone
  • isRunningOnSimulator
  • isRunningOn(_:)
  • Type of current device, based on running’s app window size.

    Uses screen size to guess device that tests are running on. May be useful if there is some device specific behaviour that has to be checked.

    Example:

    if app.deviceType == .iPhone35 {
        let button = app.buttons["more"]
        button.tap()
    }
    

    Note

    XCUIApplication already has verticalSizeClass and horizontalSizeClass that can be used to distinguish between different layouts from interface designer.

    Note

    iPhone6 and iPhone6+ have Zoom feature, which will make the resultion smaller. In this case iPhone6 would appear as iPhone 5, and iPhone6+ as iPhone 6.

    Note

    iPhone XS Max and XR have the same size in points, outside of UI tests you could differenciate them by scale (3x for XS Max and 2x for XR). For this reason property returns iPhone61 for both.

    Declaration

    Swift

    var deviceType: DeviceType { get }
  • A Boolean value indicating whether app is currently running on iPad.

    Indicates if the current device is an iPad, by checking the deviceType property.

    Example:

    if app.isRunningOnIpad {
        button.tap()
    }
    

    Declaration

    Swift

    var isRunningOnIpad: Bool { get }
  • A Boolean value indicating whether app is currently running on iPhone.

    Indicates if the current device is an iPhone, by checking the deviceType property.

    Example:

    if app.isRunningOnIphone {
        button.tap()
    }
    

    Declaration

    Swift

    var isRunningOnIphone: Bool { get }
  • A Boolean value indicating whether app is currently running on simulator.

    Indicates if tests are running inside iOS simulator, by looking for specific environment variable.

    Example:

    if app.isRunningOnSimulator {
        print("Running on simulator")
    }
    

    Declaration

    Swift

    var isRunningOnSimulator: Bool { get }
  • Type of current device, ignoring Zoom feature.

    Example:

    if app.actualDeviceType == .iPhone47 && app.deviceType == .iPhone40 {
        print("Detected iPhone 6 in zoom mode")
    }
    

    Declaration

    Swift

    var actualDeviceType: DeviceType { get }
  • Checks if current device is of provided type.

    Example:

    if app.isRunningOn(.iPhone35) {
        button.tap()
    }
    

    Declaration

    Swift

    func isRunningOn(_ deviceType: DeviceType) -> Bool

    Parameters

    deviceType

    Type of device to check for.

    Return Value

    Boolean value indicating whether current device is of the expected type.