Search code examples
iosxctestxcuitest

How to set accessibility options like "Reduce Motion" for XCTest UI tests


For an XCTest UI test, I would like to programmatically set some accessibility options that are normally set in Settings.app, taking Reduce Motion as an example. The setting can be queried like this:

// UIKit
if UIAccessibility.isReduceMotionEnabled {
    …
}

// SwiftUI
@Environment(\.accessibilityReduceMotion) private var reduceMotion

These are read-only though. I also couldn't find an API in XCUIApplication to set these accessibility flags.

Did I miss an API that would help here? Do I need to launch the Settings app in my test and let the test navigate to the Reduce Motion switch?


Solution

  • You didn't miss anything; XCUITest doesn't have any hooks into Settings.

    Do I need to launch the Settings app in my test and let the test navigate to the Reduce Motion switch?

    Yes. The bundle ID is com.apple.Preferences.