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 ?
Asked
Active
Viewed 252 times
1 Answers
2
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.

drunkencheetah
- 354
- 1
- 8
-
Thanks. But is there there a way to remove it from app switcher as well ? – learner Aug 16 '22 at 09:30
-
1You could create a swipe interaction from the bottom of the device to open the app switcher and then swipe the available apps until none are present. This will take some testing and also it will not work on older devices with a hardware button where you can't swipe from the bottom to open the app switcher. I don't see a reason to go to these lengths though, the app still being shown in the app switcher is not affecting your work in any way. – drunkencheetah Aug 16 '22 at 09:42
-
Got it. If the app is in the switcher, I am facing issues with some peripheral devices. Is there a way to create a swipe interaction from bottom of the device. Should we pass some coordinates for it ? – learner Aug 16 '22 at 09:45
-
I've updated the answer with a possible solution :) You might need to play around with the coordinates or it might not work at all – drunkencheetah Aug 16 '22 at 10:07