11

I tried to disable animation in UITests with the following code:

let app = XCUIApplication()
app.launchEnvironment = ["DISABLE_ANIMATIONS": "1"]

I also tried:

UIView.setAnimationsEnabled(false)

But it doesn't disable animation when I run UITests on simulator.

Is it because I'm using SwiftUI ?

The animation I want to disable is a view transition from one SwiftUI View to another one. Here is how I coded the transition:

NavigationLink(destination: MapView(), isActive: $viewModel.isDataLoaded) {
     EmptyView()
}

Is there another way to disable animation in UITests when using SwiftUI ?

nelson PARRILLA
  • 498
  • 1
  • 6
  • 17

1 Answers1

2

It is needed to be done explicitly (by-code) in main application, because UITests run in different process, ie. it should be like

struct YourApp: App {
    init() {
        let env = ProcessInfo.processInfo.environment
        if env["DISABLE_ANIMATIONS"] == "1" {          // << here !!
            UIView.setAnimationsEnabled(false)
        }
    }

    var body: some Scene {
      // ... scene here
    }
}

and then it can be used

let app = XCUIApplication()
app.launchEnvironment = ["DISABLE_ANIMATIONS": "1"]

Tested with Xcode 13.3 / iOS 15.4

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Asperi
  • 228,894
  • 20
  • 464
  • 690