7

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user426132
  • 1,341
  • 4
  • 13
  • 28

1 Answers1

12

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

Václav
  • 990
  • 1
  • 12
  • 28