Skip to content

Instantly share code, notes, and snippets.

@corteggo
Last active March 18, 2025 22:04
Show Gist options
  • Select an option

  • Save corteggo/e29a85d97525a85192bf9404c5171042 to your computer and use it in GitHub Desktop.

Select an option

Save corteggo/e29a85d97525a85192bf9404c5171042 to your computer and use it in GitHub Desktop.
Uninstalling app in XCUITests
/// Springboard UITests helper
/// USAGE: Springboard.uninstallApp(named: "Instagram")
internal final class Springboard {
// MARK; - Constants
/// Press duration
private static let pressDuration: Double = 1.3
/// Delete button name
private static let deleteButtonName: String = "Delete"
/// Tap offset
private static let tapOffset: Double = 0.3
// MARK: - Fields
/// Springboard application instance
internal static let springboard = XCUIApplication(privateWithPath: nil, bundleID: "com.apple.springboard")!
// MARK: - Methods
/// Kills app with given name and uninstalls it
///
/// - Parameter name: Name of the app to be uninstalled
internal static func uninstallApp(named name: String) {
XCUIApplication().terminate()
// Resolve the query for the springboard rather than launching it
springboard.resolve()
// Ensure app icon exists
let icon = springboard.icons[name]
guard icon.exists else { return }
// Long-press the icon frame
let iconFrame = icon.frame
let springboardFrame = springboard.frame
icon.press(forDuration: pressDuration)
// Tap the little "X" button at approximately where it is. The X is not exposed directly
springboard.coordinate(withNormalizedOffset: CGVector(dx: (iconFrame.minX + tapOffset) / springboardFrame.maxX, dy: (iconFrame.minY + tapOffset) / springboardFrame.maxY)).tap()
// Tap "Delete" button. Localize this if you test your app with another language.
springboard.alerts.buttons[deleteButtonName].tap()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment