zorro2b zorro2b - 1 month ago 132
Swift Question

XCTest - Waiting for predicate fails

I am trying to wait for a string to appear in the navbar during a UI test. When trying to set the expectation I get a "Thread 1: breakpoint 1.1". What am I doing wrong here?

expectation(for: NSPredicate(format: "label CONTAINS 'Rent'"),
evaluatedWith: XCUIApplication().navigationBars.staticTexts,
handler: nil)
waitForExpectations(timeout: 10, handler: nil)

Answer

Ok, I figured it out. You need an element not a query. So the code should be:

expectation(for: NSPredicate(format: "exists == 1"), 
  evaluatedWith: XCUIApplication().navigationBars.staticTexts.
  element(matching: NSPredicate(format: "label CONTAINS 'Rent'")), 
  handler: nil)
waitForExpectations(timeout: 10, handler: nil)