Simulate in XCUITest app state restoration since iOS 17

38 Views Asked by At

After migrating to iOS 17.4 I no longer able to change my application state to .runningBackgroundSuspended. So far I've been using XCUIApplication(waitForState:timeout:) and tapping on home button to move application to suspended state, then performing restarting application (see: my code below).

My question: How do you simulate app state restoration in your applications?

XCUIDevice.shared.press(XCUIDevice.Button.home)
let wentIntoBackground = app.wait(for: .runningBackgroundSuspended, timeout: timeout)
if !wentIntoBackground {
    XCTFail("App has not been sent to background, state: \(app.state)")
    return false
}
app.terminate()
let appTerminated = app.wait(for: .notRunning, timeout: timeout)
if !appTerminated {
    XCTFail("App has not been terminated, state: \(app.state)")
    return false
}
app.activate()
let startedAgain = app.wait(for: .runningForeground, timeout: timeout)
if !startedAgain {
    XCTFail("App has not been launched again, state: \(app.state)")
    return false
}
0

There are 0 best solutions below