Search code examples
swiftcoded-ui-testsxcuitest

Xcuitest - How can I wait until image finished to load


I'm running my UiTests on app that uses images/videos from the camera roll/Google photos/Etc..

All the images/videos are in CollectionView and each asset is in a specific cell.

When the app opens the "footage screen" it contains 15 assets at the same time and I'm trying to create a function that waits until all of the images finish to load.

Why do I need it: I have tests that select images/videos and sometimes the Xctest could select the first one because not all of the assets finish loading.

Note: I don't have any indication that tells me "all the assets finish to load".

Any suggestions?


Solution

    • You should inspect your app.debugDescription before and after loading. Find anything that you can asynchronously verify.

    • If necessary, add accessibility identifiers into app code, that are different before/after loading. You should also add some accessibility labels to help VoiceOver and VoiceControl users to interact with your app.

    • You can use SUITCase for screenshot testing and awaits. https://github.com/devexperts/suitcase/

    • You can add some EarlGrey 2 asserts. This testing framework is a little bit more flexible and automatically await async operations. The good thing is you can use it alongside existing XCTest tests.

    • Finally, you can just sleep(5) :D