From 673f2ba693e1210b42be52e1dadbf5259c032090 Mon Sep 17 00:00:00 2001 From: Magesh K <47920326+mahee96@users.noreply.github.com> Date: Sun, 23 Feb 2025 18:04:57 +0530 Subject: [PATCH] - UITests: Added more tests for testing repeatability --- SideStore/Tests/UITests/UITests.swift | 126 ++++++++++++++++++-------- 1 file changed, 88 insertions(+), 38 deletions(-) diff --git a/SideStore/Tests/UITests/UITests.swift b/SideStore/Tests/UITests/UITests.swift index 9a45ba68..0fc8aa8d 100644 --- a/SideStore/Tests/UITests/UITests.swift +++ b/SideStore/Tests/UITests/UITests.swift @@ -83,6 +83,21 @@ final class UITests: XCTestCase { try performRepeatabilityForStagingInputSources(for: app) } + func testRepeatabilityForStagingRecommendedSources() throws { + + let app = XCUIApplication() + app.launch() + + let systemAlert = Self.springboard_app.alerts["“\(Self.APP_NAME)” Would Like to Send You Notifications"] + + // if it exists keep going immediately else wait for upto 5 sec with polling every 1 sec for existence + XCTAssertTrue(systemAlert.exists || systemAlert.waitForExistence(timeout: 5), "Notifications alert did not appear") + systemAlert.scrollViews.otherElements.buttons["Allow"].tap() + + // Do the actual validation + try performRepeatabilityForStagingRecommendedSources(for: app) + } + // @MainActor // func testLaunchPerformance() throws { @@ -207,32 +222,18 @@ private extension UITests { private func performBulkAdd( app: XCUIApplication, - sorucesMapping: [(identifier: String, alertTitle: String, requiresSwipe: Bool)], + sourceMappings: [(identifier: String, alertTitle: String, requiresSwipe: Bool)], cellsQuery: XCUIElementQuery ) throws { - // Tap on each sorucesMapping source's "add" button. - for source in sorucesMapping { - let sourceButton = cellsQuery.otherElements - .containing(.button, identifier: source.identifier) - .children(matching: .button)[source.identifier] - _ = sourceButton.exists || sourceButton.waitForExistence(timeout: 5) // this can come from internet fetch, so give it ample time before timeout - -// let addButton = sourceButton.children(matching: .button).firstMatch - let addButton = sourceButton.children(matching: .button)["add"] - _ = addButton.exists || addButton.waitForExistence(timeout: 0.3) - addButton.tap() - - if source.requiresSwipe { - sourceButton.swipeUp(velocity: .slow) // Swipe up if needed. - } - } + // Tap on each sourceMappings source's "add" button. + try tapAddForThesePickedSources(app: app, sourceMappings: sourceMappings, cellsQuery: cellsQuery) // Commit the changes by tapping "Done". app.navigationBars["Add Source"].buttons["Done"].tap() // Accept each source addition via alert. - for source in sorucesMapping { + for source in sourceMappings { let alertIdentifier = "Would you like to add the source “\(source.alertTitle)”?" let addSourceButton = app.alerts[alertIdentifier] .scrollViews.otherElements.buttons["Add Source"] @@ -298,7 +299,7 @@ private extension UITests { ("Quantum Source\nContains all of your favorite emulators, games, jailbreaks, utilities, and more.", "Quantum Source", false), ] - try performBulkAdd(app: app, sorucesMapping: textInputSources, cellsQuery: cellsQuery) + try performBulkAdd(app: app, sourceMappings: textInputSources, cellsQuery: cellsQuery) } @@ -341,28 +342,55 @@ private extension UITests { ("Qn_'s AltStore Repo\nbit.ly/40Isul6", "Qn_'s AltStore Repo", false), ] - let repeatCount = 3 // number of times to run the entire sequence - let timeSeed = UInt64(Date().timeIntervalSince1970) - var seededGenerator = SeededGenerator(seed: timeSeed) // time is unique (upto microseconds) - uncomment this to use non-deterministic seed based RNG (random number generator) -// var seededGenerator = SeededGenerator(seed: 42) // fixed seed for deterministic start of this generator + let repeatCount = 3 // number of times to run the entire sequence + let timeSeed = UInt64(Date().timeIntervalSince1970) // time is unique (upto microseconds) - uncomment this to use non-deterministic seed based RNG (random number generator) + + try repeatabilityTest(app: app, sourceMappings: textInputSources, cellsQuery: cellsQuery, repeatCount: repeatCount, seed: timeSeed) + } + + private func repeatabilityTest( + app: XCUIApplication, + sourceMappings: [(identifier: String, alertTitle: String, requiresSwipe: Bool)], + cellsQuery: XCUIElementQuery, + repeatCount: Int = 1, // number of times to run the entire sequence + seed: UInt64 = 42 // default = fixed seed for deterministic start of this generator + ) throws { + let seededGenerator = SeededGenerator(seed: seed) for _ in 0..