这个测试失败是因为
exceeds maximum length of 128 characters. You can work around this
limitation by constructing a query with a custom NSPredicate that
specifies the property (label, title, value, placeholderValue, or
identifier) to match against.'
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 个字符的限制。
Best Answer-推荐答案 strong>
您可以使用 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)
更多:
How to test that staticTexts contains a string using XCTest
这里:https://developer.apple.com/documentation/foundation/nspredicate
关于ios - UI 测试 Xcode 中的 128 个字符限制,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/53501517/
|