Skip to content

Commit

Permalink
Enable visionOS 2.0 Support for Deleting an App from RealityLauncher
Browse files Browse the repository at this point in the history
  • Loading branch information
PSchmiedmayer committed Aug 3, 2024
1 parent cc2705f commit ef30fc3
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions Sources/XCTestExtensions/XCUIApplication+DeleteAndLaunch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,34 @@ extension XCUIApplication {
XCTAssertTrue(springboard.icons[appName].firstMatch.isHittable)

Check failure on line 49 in Sources/XCTestExtensions/XCUIApplication+DeleteAndLaunch.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS / Test using xcodebuild or run fastlane

testDeleteAndLaunchFromFirstPage, XCTAssertTrue failed
springboard.icons[appName].firstMatch.press(forDuration: 1.75)

if !springboard.collectionViews.buttons["Remove App"].waitForExistence(timeout: 10.0) && springboard.state != .runningForeground {
// The long press did not work, let's launch the springboard again and then try long pressing the app icon again.
springboard.activate()

sleep(2)

XCTAssertTrue(springboard.icons[appName].firstMatch.isHittable)
springboard.icons[appName].firstMatch.press(forDuration: 1.75)

XCTAssertTrue(springboard.collectionViews.buttons["Remove App"].waitForExistence(timeout: 10.0))
}
if #available(visionOS 2.0, *) {
// VisionOS 2.0 changed the behavior how apps are deleted, showing a delete button above the app icon.
sleep(5)
let deleteButtons = springboard.collectionViews.buttons.matching(identifier: "Delete")
// There is no isEmtpy property on the `XCUIElementQuery`.
// swiftlint:disable:next empty_count
if deleteButtons.count > 0 {
// We assume that the latest installed app is on the trailing part of the screen and therefore also the last button.
let lastDeleteButton = deleteButtons.element(boundBy: deleteButtons.count - 1)
lastDeleteButton.tap()
} else {
XCTFail("No 'Delete' buttons found")

Check failure on line 63 in Sources/XCTestExtensions/XCUIApplication+DeleteAndLaunch.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS / Test using xcodebuild or run fastlane

testDeleteAndLaunch, failed - No 'Delete' buttons found
}
} else {
if !springboard.collectionViews.buttons["Remove App"].waitForExistence(timeout: 10.0) && springboard.state != .runningForeground {
// The long press did not work, let's launch the springboard again and then try long pressing the app icon again.
springboard.activate()

sleep(2)

XCTAssertTrue(springboard.icons[appName].firstMatch.isHittable)
springboard.icons[appName].firstMatch.press(forDuration: 1.75)

XCTAssertTrue(springboard.collectionViews.buttons["Remove App"].waitForExistence(timeout: 10.0))
}

springboard.buttons["Remove App"].tap()
springboard.buttons["Remove App"].tap()
}

#if os(visionOS)
// alerts are running in their own process on visionOS (lol). Took me literally 3 hours.
Expand Down

0 comments on commit ef30fc3

Please sign in to comment.