XCTest in Xcode 16
The first is
waitForNonExistence(withTimeout:)
, which provides the inverse of the existingwaitForExistence(timeout:)
API. Finally! This is such a welcome change. Often in UI testing it is more semantic to wait for an element to disappear rather than appear — for example, waiting for a loading indicator or waiting for aUIContentUnavailableView
to disappear. Previously, you would have to roll your own implementation or awkwardly usewaitForExistence(timeout:)
and negate the result — both options are cumbersome and inefficient.[…]
The second new API is
wait(for:toEqual:timeout:)
, which waits for a property value of an element to equal a new value. This is useful for when the contents of an existing view should be updated and you want to verify the update happened. The most common use case here is likely for checking the contents of labels, text fields, or text views that change based on state updates or user interaction. Previously, there was not a great way to achieve this without introducing artificial timeouts in your test, or changing the UI element’s.accessibilityIdentifier
in your app when its contents updated and then checking for the existence of the new identifier.
But he says that the latter currently doesn’t work.
Previously: