user426132
user426132

Reputation: 1441

128 character limit in UI test Xcode

This test in failing because

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)
    }

How could I convert this so that I could work around the 128 char limit while testing the validity of the text.

Upvotes: 7

Views: 2994

Answers (1)

V&#225;clav
V&#225;clav

Reputation: 1000

You can use label LIKE for your full string:

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)

Or you can use label CONTAINS for part of your string:

 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)

More here: How to test that staticTexts contains a string using XCTest

and here: https://developer.apple.com/documentation/foundation/nspredicate

Upvotes: 12

Related Questions