I have a button that sends the user to the Maps app and I want to check if the user left the app. Any idea how I can check this? I tried adding an AssertFalse using an element from app under test, but it does not work as it can't retrieve the elements of the app since it's not in focus.
Asked
Active
Viewed 894 times
1
-
I would try to set a visible expectation to the self.view.window and observe if it changes to false. See how here: http://masilotti.com/ui-testing-cheat-sheet/ – Bence Pattogato Jun 07 '17 at 11:40
-
I tried that solution ( i guess you refer to the section "How to Assert a View is On the Screen"), but seams to work only if you want to check the switch between 2 views or windows within the app. – ioana Jun 07 '17 at 12:10
-
Then add an expectation for the notification: AppWillEnterBackground in your UI test with long timeout (https://stackoverflow.com/questions/9011868/whats-the-best-way-to-detect-when-the-app-is-entering-the-background-for-my-vie) – Bence Pattogato Jun 07 '17 at 12:24
1 Answers
2
In iOS 11, you can do this using XCUIApplication.state
to see if the app is in the background or foreground, but this isn't possible in Swift 3 and below.

Oletha
- 7,324
- 1
- 26
- 46
-
-
2This is not a Swift feature. That's an iOS 11 feature. This also works with ObjC in iOS 11. – dasdom Jun 11 '17 at 06:09
-