【发布时间】:2016-10-23 03:13:15
【问题描述】:
我正在尝试在一个基本的购物清单应用程序中构建一个 UI 测试,以确保通过滑动删除表格视图单元格实际上会从表格视图中删除该单元格。
我正在运行下面的测试代码,但是当需要向左滑动表格视图单元格(以显示删除按钮)时,它不会滑动。看起来它可能正在点击它,但它没有滑动。因此,尝试点击删除按钮时测试失败,因为“没有找到按钮匹配项”。
如何在表格视图中进行一次测试滑动删除?
func testDeletingCell() {
let app = XCUIApplication()
app.navigationBars["ShoppingList.ShoppingListView"].buttons["Add"].tap()
let element = app.otherElements.containing(.navigationBar, identifier:"ShoppingList.AddShoppingListItemView").children(matching: .other).element.children(matching: .other).element.children(matching: .other).element
let textField = element.children(matching: .textField).element(boundBy: 0)
textField.tap()
textField.typeText("abc")
let textField2 = element.children(matching: .textField).element(boundBy: 1)
textField2.tap()
textField2.typeText("123")
app.navigationBars["ShoppingList.AddShoppingListItemView"].buttons["Save"].tap()
let tablesQuery = app.tables
tablesQuery.children(matching: .cell).element(boundBy: 0).staticTexts["123"].swipeLeft()
tablesQuery.buttons["Delete"].tap()
XCTAssert(app.tables.cells.count == 0)
}
【问题讨论】:
-
是否正确找到了 123 元素?如果你看模拟器,它真的被刷了吗?
标签: ios swift uitableview xcode-ui-testing