简体   繁体   English

iOS XCUITest - 如何使用 xcuitest 从应用切换器中删除应用?

[英]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).我正在尝试使用 xcuitest 从应用程序切换器中删除一个应用程序(基本上杀死该应用程序)。 The issue is app.terminate() just terminates it and puts it on background mode.问题是 app.terminate() 只是终止它并将其置于后台模式。 Since there is no press on home action on new iPhones, there is a way to swipe up from the bottom of the screen?既然新 iPhone 上没有按 Home 动作,那有办法从屏幕底部向上滑动吗?

app.terminate() does actually kill the app, it does not put it in background mode. app.terminate()实际上会杀死应用程序,它不会将其置于后台模式。 What you see in the app switcher is a leftover snapshot of the running app but it is not actually running.您在应用程序切换器中看到的是正在运行的应用程序的剩余snapshot ,但它实际上并未运行。 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:打开 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") .我建议您使用app.terminate() ,然后使用let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")为跳板创建一个新的 XCUIApplication 实例。 You can then call this function like this springboard.openDock() to open the Dock/App switcher (I am assuming).然后,您可以像此springboard.openDock()一样调用此 function 来打开 Dock/App 切换器(我假设)。 If it works then after you open it you can experiment with springboard.swipeUp() to close all available apps.如果它有效,那么在您打开它之后,您可以尝试使用springboard.swipeUp()来关闭所有可用的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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