How to deal with animation in UITests in iOS

Issue #143

Today I was writing tests and get this error related to app idle

1
t =    23.06s         Assertion Failure: <unknown>:0: Failed to scroll to visible (by AX action) Button, 0x6000003827d0, traits: 8858370049, label: 'cart', error: Error -25204 performing AXAction 2003 on element <XCAccessibilityElement: 0x7fc391a2bd60> pid: 91461, elementOrHash.elementID: 140658975676048.128

It turns out that the project uses a HUD that is performing some progress animation. Even it was being called HUD.hide(), the problem still exists.

1
2
3
4
t =    31.55s     Wait for no.example.MyApp to idle
t = 91.69s App animations complete notification not received, will attempt to continue.
t = 91.70s Tap Target Application 0x6040002a1260
t = 91.70s Wait for no.example.MyApp to id

No matter how I call sleep,wait`, still the problem

1
2
3
sleep(10)
app.tap()
_ = checkoutButton.waitForExistence(timeout: 10)

The fix is to disable animation. Start with setting argument when running tests

1
2
app.launchArguments.append("--UITests")
app.launch

Then in AppDelegate

1
2
3
4
5
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if CommandLine.arguments.contains("--UITests") {
UIView.setAnimationsEnabled(false)
}
}

Comments