Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make an XCTest Expectation without failing?

I am using Xcode 7, Swift UI Automation. I need to wait for a UIButton to appear in my home screen. I set an expectation for "exists == 1".

This UIButton sometimes appears, sometime it doesn't. During my UI test, if the element appears, everything is OK. But if the element does not appear, the expectation fails (and I don't want it to fail, I just need to take another flow of action)

How can I make a decision withour the test actually failing?

like image 514
Herno Avatar asked Dec 18 '25 12:12

Herno


1 Answers

you have to wait for the expectation and handle it if this doesn't happens do something else into the brackets.

let exists = NSPredicate(format: "exists == 1")
expectationForPredicate(exists, evaluatedWithObject: UIButton, handler: nil)
waitForExpectationsWithTimeout(10) { error in

   somethings else
}

Cheers

like image 154
emoleumassi Avatar answered Dec 21 '25 04:12

emoleumassi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!