每次Apple发布新的XCode版本时,我的UI测试都会失败。而且我需要花几天的时间弄清楚测试中需要更改的内容。
我有什么想念的吗?
例:
let tablesQuery = app.tables
let passwordCellsQuery = tablesQuery.cells.containing(.staticText, identifier:"Password")
passwordCellsQuery.children(matching: .secureTextField).element.tap()
passwordCellsQuery.children(matching: .secureTextField).element.typeText("12345678")
let memorableDateDdMmYyyyCellsQuery = tablesQuery.cells.containing(.staticText, identifier:"Memorable Date (dd/mm/yyyy)")
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 2).tap()
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 2).typeText("1")
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 0).tap()
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 0).typeText("2")
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 1).tap()
memorableDateDdMmYyyyCellsQuery.children(matching: .secureTextField).element(boundBy: 1).typeText("3")
这次,我收到“无法合成事件:元素或任何后代都没有键盘焦点。事件调度快照:SecureTextField”
我已经害怕了所有新的XCode版本,因为它总是破坏了我的所有UI测试,这次是11.4.1版(11E503a)。
单元测试的表现(值得庆幸)。
您不应该坚持使用自动生成的代码。
自己编写测试代码和元素的描述-这样您的测试将更加稳定。
尝试使您的代码更简单-它将更易于维护。
let table = app.tables.element
let passwordCell = table.cells["Password"]
passwordCellsQuery.tapAndType("12345678")
let dateCell = table.cells["Memorable Date (dd/mm/yyyy)"]
dateCell.secureTextFields.element(boundBy: 2).tapAndType("1")
dateCell.secureTextFields.element(boundBy: 0).tapAndType("2")
dateCell.secureTextFields.element(boundBy: 1).tapAndType("3")
extension XCUIElement {
func tapAndType(_ text: String) {
tap()
typeText(text)
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句