BadmintonCat
BadmintonCat

Reputation: 9586

XCUITest - Task-kill App

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?

Upvotes: 1

Views: 979

Answers (2)

iamMobile
iamMobile

Reputation: 969

Instead of depending on Springboard and double tap try this (I assume you are trying to close the app and not uninstall it)

closeApp(background: Bool = false) {
if (background) {
     XCUIDevice.shared().press(.home)
} else {
 application.terminate()
}

Upvotes: 2

Mladen
Mladen

Reputation: 2210

Quickly double-tapping home button is still not possible to achieve.

Upvotes: 0

Related Questions