工作解决方案为iOS 14
import XCTest\n\nlet springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")\n\nfunc deleteMyApp() {\n XCUIApplication().terminate()\n\n let bundleDisplayName = "MyApp"\n\n let icon = springboard.icons[bundleDisplayName]\n if icon.exists {\n icon.press(forDuration: 1)\n\n let buttonRemoveApp = springboard.buttons["Remove App"]\n if buttonRemoveApp.waitForExistence(timeout: 5) {\n buttonRemoveApp.tap()\n } else {\n XCTFail("Button \\"Remove App\\" not found")\n }\n\n let buttonDeleteApp = springboard.alerts.buttons["Delete App"]\n if buttonDeleteApp.waitForExistence(timeout: 5) {\n buttonDeleteApp.tap()\n }\n else {\n XCTFail("Button \\"Delete App\\" not found")\n }\n\n let buttonDelete = springboard.alerts.buttons["Delete"]\n if buttonDelete.waitForExistence(timeout: 5) {\n buttonDelete.tap()\n }\n else {\n XCTFail("Button \\"Delete\\" not found")\n }\n }\n}\n\nclass HomeUITests: XCTestCase {\n override func setUpWithError() throws {\n // Put setup code here. This method is called before the invocation of each test method in the class.\n\n // In UI tests it is usually best to stop immediately when a failure occurs.\n continueAfterFailure = false\n\n // In UI tests it\xe2\x80\x99s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.\n }\n\n override func tearDownWithError() throws {\n // Put teardown code here. This method is called after the invocation of each test method in the class.\n }\n\n func testExample() throws {\n deleteMyApp()\n\n // UI tests must launch the application that they test.\n let app = XCUIApplication()\n app.launch()\n\n // Use recording to get started writing UI tests.\n // Use XCTAssert and related functions to verify your tests produce the correct results.\n }\n\n func testLaunchPerformance() throws {\n if #available(macOS 10.15, iOS 13.0, tvOS 13.0, *) {\n // This measures how long it takes to launch your application.\n measure(metrics: [XCTApplicationLaunchMetric()]) {\n XCUIApplication().launch()\n }\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n
尝试按应用程序图标比以前的 iOS 版本长一点。
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()
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6176 次 |
| 最近记录: |