由于,此测试失败
超过了128个字符的最大长度。你可以解决这个问题通过使用自定义NSPredcate构造查询来限制指定属性(标签、标题、值、占位符值或标识符(进行匹配。'
func testMessage() {
app.buttons["BEGIN"].tap()
let tablesQuery = app.tables
XCTAssert(tablesQuery.children(matching: .cell).element(boundBy: 0).staticTexts["<EXTREMELY LONG TEXT HERE (200chars)>"].exists)
}
我如何转换它,以便在测试文本的有效性时绕过128个字符的限制。
您可以将label LIKE
用于完整字符串:
let yourSuperLongText = "your super long string"
let predicate = NSPredicate(format: "label LIKE %@", yourSuperLongText)
let element = tablesQuery.children(matching: .cell).element(boundBy: 0).staticTexts.element(matching: predicate)
XCTAssert(element.exists)
或者,您可以使用label CONTAINS
作为字符串的一部分:
let partOfYoursSuperLongText = "part of your super long string"
let predicate = NSPredicate(format: "label CONTAINS[c] %@", partOfYoursSuperLongText)
let element = tablesQuery.children(matching: .cell).element(boundBy: 0).staticTexts.element(matching: predicate)
XCTAssert(element.exists)
更多信息:如何使用XCTest 测试staticTexts是否包含字符串
在这里:https://developer.apple.com/documentation/foundation/nspredicate