0

Trying to find a solution to automate task-kill the app for XCUITest...

static let springboard:XCUIApplication? = XCUIApplication(bundleIdentifier: "com.apple.springboard")

class func killApp(app:XCUIApplication) -> Bool
{
    app.terminate()
    if let springboard = springboard
    {
        springboard.activate()
        XCUIDevice.shared.press(.home)
        XCUIDevice.shared.press(.home)
        Thread.sleep(forTimeInterval: 1.0)
        let appTask = app.otherElements["appID"]
        if appTask.isHittable
        {
            appTask.swipeUp()
            XCUIDevice.shared.press(.home)
            return true
        }
        else
        {
            print("App task is not hittable!")
            return false
        }
    }
    return false
}

But it's not working. The two home button taps seem not to be recognized as a quick double-tap. Does anyone know a workable solution for this?

4

2 回答 2

1

不要依赖 Springboard 和双击试试这个(我假设你试图关闭应用程序而不是卸载它)

closeApp(background: Bool = false) {
if (background) {
     XCUIDevice.shared().press(.home)
} else {
 application.terminate()
}
于 2018-09-24T16:52:31.237 回答
0

快速双击主页按钮仍然无法实现。

于 2017-11-24T08:51:23.630 回答