I have tried writing UITests in Xcode 8 using Swift 3 for a really simple todo app. The app displays a UIALertView with a text field and two buttons (Cancel and Add). Here is my attempt at a UITest:
func testExample() {
print("Tests Started")
let app = XCUIApplication()
app.navigationBars["To Do"].buttons["Add"].tap()
print("+ button clicked")
if app.alerts.element.collectionViews.buttons["Add"].exists {
let addAlert = app.alerts
let textField = addAlert.textFields.element
textField.typeText("Cheese")
app.alerts.element.collectionViews.buttons["Add"].tap()
print("Add button clicked")
}
let tablesQuery = app.tables
let count = tablesQuery.cells.count
print("CELL COUNT: \(count)")
print("tests finished")
}
The problem is that when the test is run the dialog box appears but no text is entered and the cell count shows no new item has been added. I'm not sure why this is.