UI 测试 Xcode 中的 128 个字符限制

128 character limit in UI test Xcode

此测试失败,因为

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)

更多信息在这里:

这里:https://developer.apple.com/documentation/foundation/nspredicate