Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable visionOS 2.0 Support for Deleting an App from RealityLauncher #24

Merged
merged 2 commits into from
Aug 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions Sources/XCTestExtensions/XCUIApplication+DeleteAndLaunch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
preconditionFailure("Unsupported platform.")
#endif
}

private static var visionOS2: Bool {
#if os(visionOS)
if #available(visionOS 2.0, *) {
true
} else {
false
}
#else
false
#endif
}

/// Deletes the application from the iOS springboard (iOS home screen) and launches it after it has been deleted and reinstalled.
/// - Parameter appName: The name of the application as displayed on the springboard (iOS home screen).
Expand All @@ -49,19 +61,34 @@
XCTAssertTrue(springboard.icons[appName].firstMatch.isHittable)
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 XCUIApplication.visionOS2 {
// 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 warning on line 76 in Sources/XCTestExtensions/XCUIApplication+DeleteAndLaunch.swift

View check run for this annotation

Codecov / codecov/patch

Sources/XCTestExtensions/XCUIApplication+DeleteAndLaunch.swift#L65-L76

Added lines #L65 - L76 were not covered by tests
} 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))

Check warning on line 87 in Sources/XCTestExtensions/XCUIApplication+DeleteAndLaunch.swift

View check run for this annotation

Codecov / codecov/patch

Sources/XCTestExtensions/XCUIApplication+DeleteAndLaunch.swift#L79-L87

Added lines #L79 - L87 were not covered by tests
}

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
Loading