Skip to content

Instantly share code, notes, and snippets.

@anzfactory
Last active April 1, 2020 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anzfactory/4ce75360abc38167a58d978bdf713c2e to your computer and use it in GitHub Desktop.
Save anzfactory/4ce75360abc38167a58d978bdf713c2e to your computer and use it in GitHub Desktop.
XCUITestでアプリ削除するやつ
func deleteApp() {
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
springboard.activate()
let appName = "MyApp"
// ホームから該当アプリ探す
let appIcon = springboard.icons[appName]
guard appIcon.exists else {
return
}
// アプリアイコンを長押
appIcon.press(forDuration: 1.3)
if #available(iOS 13.2, *) {
// 13.2 からはポップアップ表示されるメニューから削除指定可能
springboard.buttons["Delete App"].firstMatch.tap()
} else {
if #available(iOS 13.0, *) {
// 13+ だと並び替えるを一旦選択してからぷるぷる状態へ移行する
springboard.buttons["Rearrange Apps"].firstMatch.tap()
}
// アプリアイコンの右上にでるバツボタンをタップで削除してい
let iconFrame = appIcon.frame
let springboardFrame = springboard.frame
springboard.coordinate(withNormalizedOffset: CGVector(dx: ((iconFrame.minX + 9) / springboardFrame.maxX), dy:((iconFrame.minY + 9) / springboardFrame.maxY))).tap()
Thread.sleep(forTimeInterval: 1.5)
}
// 確認アラートが出てくるのでタップして削除
springboard.buttons["Delete"].firstMatch.tap()
Thread.sleep(forTimeInterval: 1.5)
if #available(iOS 13.2, *) { } else {
// アイコンぷるぷる状態解除
XCUIDevice.shared.press(.home)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment