I'm sure there is a simple solution but I don't know how to achieve it. I'm writing UI Unit testing for my iOS Application (currently in Objective C but happy for a Swift solution too) so that I can use Fastlane's snapshot
command but since the application is cloud based simply switching between tabs/views and taking screen shots wouldn't work because the screen shots will only have "Loading..." where as I'd like valid data in them.
My current solution is ugly and unreliable. Currently I'm just waiting 3 seconds via sleep(3)
and then proceeding. I'm using AFNetworking to perform the requests so I'm just I can just listen to any HTTP request that comes in and if it matches the one I want I can proceed but I'm not sure:
Any ideas or help would be greatly appreciated because I don't fancy taking hundreds of screen shots manually =)
Effective UI Tests are written with a different mindset than unit tests and production code. UI Tests should be written from the user's perspective and not care what goes on "under the hood" of the app. For example, your test should wait for a specific UI element to appear instead of waiting for an NSNotification to fire or a specific network request to complete.
Let's say your first tab/screen displays user information. Contained in that data is the user's username. You can use XCTest's asynchronous testing API to pause the framework until the element is found (or a timeout occurs).
let app = XCUIApplication()
let username = self.app.staticTexts["joemasilotti"]
let exists = NSPredicate(format: "exists == true")
expectationForPredicate(exists, evaluatedWithObject: username, handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)
XCTAssert(username.exists)
This comes directly from a UI Testing cheat sheet I put together. It also has a working example app that you can run in Xcode and play around with the code and tests.