In Xcode UI testing, how do I test that staticTexts contains a string?
In the debugger, I can run something like this to print out all the content of staticTexts:
I had this problem while I was building my XCTest, I had a dynamic string inside of my block of text I should verify. I had built this two functions to solve my problem:
func waitElement(element: Any, timeout: TimeInterval = 100.0) {
let exists = NSPredicate(format: "exists == 1")
expectation(for: exists, evaluatedWith: element, handler: nil)
waitForExpectations(timeout: timeout, handler: nil)
}
func waitMessage(message: String) {
let predicate = NSPredicate(format: "label CONTAINS[c] %@", message)
let result = app.staticTexts.containing(predicate)
let element = XCUIApplication().staticTexts[result.element.label]
waitElement(element: element)
}
I know this post is old, but I hope this can help someone.