问题
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