我尝试使用Swift 3在Xcode 8中编写UITests,这是一个非常简单的待办事项应用程序。该应用程序显示带有文本字段和两个按钮(取消和添加)的UIALertView。这是我在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")
}
问题是,当运行测试时,会出现一个对话框但没有输入任何文本,并且单元格计数显示没有添加任何新项目。我不确定为什么会这样。