How to delete/reset an app from iOS 13 with XCTest?

扶醉桌前 提交于 2020-08-03 08:16:37

问题


Recently I started testing an iOS app using XCTest but I found some difficulties, the main difficulty was deleting or resetting the app content in each test class.

I'm currently using XCode 11 and trying to delete/reset an app from iOS 13 for each test class, I've already tried:

  • Delete app through springboard
  • Delete app by going to the app settings

This step is really important in my tests because in each test I need to create a profile and log in, so in the next test I need to have the app just installed from scratch


回答1:


Try to press the app icon a little longer than in previous iOS versions.

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

    func deleteMyApp() {
        XCUIApplication().terminate()

        let icon = springboard.icons["YourAppName"]
        if icon.exists {
            let iconFrame = icon.frame
            let springboardFrame = springboard.frame
            icon.press(forDuration: 5)

            // Tap the little "X" button at approximately where it is. The X is not exposed directly
            springboard.coordinate(withNormalizedOffset: CGVector(dx: (iconFrame.minX + 3) / springboardFrame.maxX, dy: (iconFrame.minY + 3) / springboardFrame.maxY)).tap()

            springboard.alerts.buttons["Delete"].tap()
        }
    }



回答2:


enum Springboard {

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

    static func deleteApp() {
        XCUIApplication().terminate()

        let icon = springboardApp.icons[appName]
        if icon.exists {
            icon.press(forDuration: 3)
            icon.buttons["DeleteButton"].tap()

            springboardApp.alerts.buttons["Delete"].tap()
        }
    }
 }


来源:https://stackoverflow.com/questions/58509372/how-to-delete-reset-an-app-from-ios-13-with-xctest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!