Contents

XCUIDevice

A proxy that can simulate physical buttons, device orientation, and Siri interaction for an iOS, watchOS, or tvOS device.

Declaration

@MainActor class XCUIDevice

Overview

Use the XCUIDevice shared instance to perform the following interactions with a simulated iOS, watchOS, or tvOS device during a UI test:

  • Press the volume, home, camera, and action buttons.

  • Rotate the device.

  • Turn the Digital Crown on a watchOS device.

  • Determine whether the iOS device supports pointer interaction.

  • Activate Siri.

This example shows a test that determines whether the action button is available on the shared device and, if it is, simulates pressing the button:

@MainActor
func testPressingActionButton() throws {
    let device = XCUIDevice.shared
    try XCTSkipUnless(device.hasHardwareButton(.action),
                  "The device doesn't have an action button.")
    let app = XCUIApplication()
    app.launch()
    device.press(.action)
    // Assert that your app responds correctly.
}

XCUIDevice is available in iOS, watchOS, and tvOS.

Topics

Accessing the current device

Interacting with buttons and the Digital Crown

Performing gestures

Rotating and changing location

Interacting with the OS

Interacting with Siri

Deprecated

See Also

Device simulation