zorro2b
zorro2b

Reputation: 2257

How to wait for UI element without failing test case

I have a dialog that displays on first execution of my app. I therefore want my test case to handle responding to the dialog - but only if it appears.

The waitForExpectations method will error out if the timeout is reached.

What is the best way to wait for this element to appear for a short time without failing the test case if it does not appear?

Upvotes: 0

Views: 498

Answers (2)

MobileTuts
MobileTuts

Reputation: 1

Try the following code:

addUIInterruptionMonitorWithDescription("SYSTEM_DESCRIPTION") { (alert) -> Bool in
  alert.buttons["BUTTON_TITLE"].tap()
  return true
}

app.buttons["BUTTON_TITLE"].tap()
app.tap() 

SYSTEM_DESCRIPTION is the title or description of system alert.

BUTTON_TITLE is like "OK", "Allow", ...

Find out more in this answer: https://stackoverflow.com/a/32228033/6657951

Upvotes: 0

Aaron Sofaer
Aaron Sofaer

Reputation: 726

You will have to reimplement waiting. As terrible as it sounds, I recommend using Sleep and If statements; you want to lock your test thread while it waits for the app to finish presenting content, then evaluate.

Unfortunately, as far as I'm aware none of the options for waitForExpectationsWithTimeout permit you to not fail the test if the expectationForPredicate is not fulfilled at the end of the timeout time.

Upvotes: 0

Related Questions