【问题标题】:128 character limit in UI test XcodeUI 测试 Xcode 中的 128 个字符限制
【发布时间】:2019-04-29 07:15:45
【问题描述】:

这个测试失败是因为

超过 128 个字符的最大长度。你可以解决这个问题 通过使用自定义 NSPredicate 构造查询来限制 指定属性(标签、标题、值、占位符值或 标识符)来匹配。'

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 个字符的限制。

【问题讨论】:

    标签: ios xctest xcuitest


    【解决方案1】:

    您可以使用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

    【讨论】:

    • 这也是 UITests 128 个字符限制的一个很好的解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-13
    • 1970-01-01
    • 2015-10-14
    • 2016-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多