Im writing a UITest to check if a List of Countries populated in my tableview are displayed in ascending order. I am populating the countries from Countries api
The purpose of my UITest is to check the countries are displayed in alphabetical order, so I pick ten countries at random in ascending order of table index and confirm that the countries are in ascending order too.
let table = app.tables["CountryTable"]
XCTAssertTrue(table.waitForExistence(timeout: kTimeOut))
let cells = table.cells.allElementsBoundByIndex
var indexes = Set<UInt32>()
while indexes.count < 10 {
indexes.insert(arc4random_uniform(UInt32(cells.count)))
}
let orderedIndexes = Array(indexes).sorted()
let countries = orderedIndexes.map { (index) -> String in
return cells[Int(index)].staticTexts["Country"].label
}
let orderedCountries = countries.sorted()
XCTAssertEqual(countries, orderedCountries)
In my ViewController i can see that the countries are sorted in ascending order, but my Test is failing.
i will be glad to be educated on how to test this approach appropriately and make the Test pass.