IGListKit/Examples/Examples-iOS/IGListKitExamples-UITests/LoadMoreViewControllerUITests.swift
Tim Oliver ce09fad401 Harden iOS UI tests to catch potential infinite loops
Summary:
During testing, I noticed some of the UI tests would hang, and the runner would spin for hours.

I'm not sure if this was due to any code changes I made to the sample apps, or if it was just a general change in Xcode 15, but I discovered that some of the UI tests were using a for loop to 'flick' the screen until a UI element came on screen. For whatever reason, the for loop exit condition stopped working, and so now the test was stuck in an infinite loop.

This diff changes the exit condition so it properly works now, and also adds a maximum number of allowed 'flicks' just to absolutely guarantee an infinite loop isn't possible.

Reviewed By: fethica

Differential Revision: D50294913

fbshipit-source-id: 77b789e45cc935735b13192843aa80f512dbd7d8
2023-10-13 22:50:38 -07:00

32 lines
1 KiB
Swift

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import XCTest
final class LoadMoreViewControllerUITests: UITestCase {
func test_whenScrollingToTheBottom_thatNewItemsAreLoaded() {
let collectionViews = XCUIApplication().collectionViews
collectionViews.cells.staticTexts["Tail Loading"].tap()
// Swipe up until the last item in the list is on-screen
var numberOfTries = 0
let lastElem = collectionViews.cells.staticTexts["15"]
while !lastElem.isHittable {
collectionViews.element.swipeUp()
numberOfTries += 1
if numberOfTries >= 10 {
break
}
}
// Wait for the following item to be loaded asynchronously
let newlyLoadedElement = collectionViews.cells.staticTexts["16"]
waitToAppear(element: newlyLoadedElement, timeout: 30.0)
}
}