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

标签 ios xctest xcuitest

这个测试失败是因为

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/

相关文章:

ios - Chartboost 委托(delegate)错误

ios - NSOperationQueue在网络切换时取消当前的NSOperation

ios - 可以从 XCTest 中的其他测试用例中调用测试用例

swift - 在 Xcode UI Test 中定位没有辅助功能 ID 的元素

ios - 是否可以在 iOS UI 测试中模拟两指滑动?

jQuery 滚动到 iOS 地址栏顶部

ios - 临时存档时 RestKit 链接错误

swift - Xcode 11 : _XCTestCaseInterruptionException when using XCUIElement waitForExistence

ios - Xcode XCTestCase 根本没有运行

ios - 未能安装或启动 jenkins 中的测试运行程序错误