简体   繁体   中英

iOS XCUITest - How to remove an app from the app switcher using xcuitest?

I am trying to remove an app from the app switcher using xcuitest (basically kill the app). The issue is app.terminate() just terminates it and puts it on background mode. Since there is no press on home action on new iPhones, there is a way to swipe up from the bottom of the screen?

app.terminate() does actually kill the app, it does not put it in background mode. What you see in the app switcher is a leftover snapshot of the running app but it is not actually running. If you tap on it, then the app is relaunched which might make you think that it was on background mode. A possible example to open the Dock:

extension XCUIApplication {
  func openDock() {
    let swipeStart = coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.999))
    let swipeEnd = coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.001))
    swipeStart.press(forDuration: 0.1, thenDragTo: swipeEnd)
  }
}

I would advise you use app.terminate() , then create a new XCUIApplication instance for springboard with let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") . You can then call this function like this springboard.openDock() to open the Dock/App switcher (I am assuming). If it works then after you open it you can experiment with springboard.swipeUp() to close all available apps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM