Reputation: 93
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.
Upvotes: 1
Views: 1065
Reputation: 1
In my case I had to check if the app has opened Safari. Solution by checking XCUIApplication.state didn't work for me, because the app was somehow still .runningForeground
when debugging.
I found out that you can create instance of Safari inside of your test using XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
, so the following assert helped me to check that Safari opens after openin external link from app:
XCTAssert(
XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
.wait(for: .runningForeground, timeout: 1)
)
Upvotes: 0
Reputation: 7659
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.
Upvotes: 2