I have a collectionview that has 8 cells. Each cell has a label that contains some different text. I want to test if each cell contains a label with the correct text. I'm using a loop to go through each text and asset if a cell containing that text exists.
The problem is that the 7th & 8th cells (indices 6 & 7) are off-screen so the test fails.
let names = ["First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth"]
for name in names {
let cellWithName = app.cells.containing(.staticText, identifier: name).element
XCTAssert(cellWithName.exists)
}
I was given a solution: to restrict the names array to only the first 6 names, then create another array with the last 2 names and test them separately when on on-screen, but I can already imagine a whole host of problems with this solution.
Does anyone know a better solution to testing UI elements that are off-screen?