Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 395
user426132 Avatar asked Nov 27 '18 14:11

user426132


1 Answers

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

like image 130
Václav Avatar answered Nov 10 '22 23:11

Václav