这个测试失败是因为
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 个字符的限制。
最佳答案
您可以使用 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/