Updated Roman's answer to support iOS 13 on iPad.
By inserting otherElements["Home screen icons"]
, the code works both of iPhone and iPad.
class Springboard {
static let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
class func deleteMyApp() {
XCUIApplication().terminate()
// Insert otherElements["Home screen icons"] here
let icon = springboard.otherElements["Home screen icons"].icons["Workoutimer"]
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()
XCUIDevice.shared.press(XCUIDevice.Button.home)
}
}
}
Misc.
On iPad, "recent launched app" will be added to the right side of the Dock. This iPad specific behavior leads XCUITest finds two elements if you search icons only by its identifier.
Your app will be added here, too.
To handle that, specify otherElements["Home screen icons"]
and it excludes elements of the "Dock".