I am using swift for an Xcode UI Test app. Our application under test sometimes pops up an "Alert Box" that affects normal work flow of test case. There is no way of predicting when the popup would appear. It might appear at test case 1 or test case number x.
I wanted to dismiss the "Alert Box" and continue with rest of the test case. How do I handle similar event of ASYNC nature with swift XCUITest framework, without affecting normal flow of test case?
So far I have found:
expectationForPredicate(exists, evaluatedWithObject: alertbox, handler: nil)
waitForExpectationsWithTimeout(300, handler: nil)
This is not feasible because of two reasons.
- timeout cannot be predicted
Is blocking test case flow
func testTestCase1 { let expectation = expectationWithDescription("Alert Found! Dismissing") do { // ... // test steps // ... expectation.fulfill() } waitForExpectationsWithTimeout(300) { dimissAlert() } }
Ref1:
https://www.bignerdranch.com/blog/asynchronous-testing-with-xcode-6/
Ref2:
XCTest and asynchronous testing in Xcode 6
Ref3: https://adoptioncurve.net/archives/2015/10/testing-asynchronous-code-in-swift/
Is there a generic way to handle async events across the suite? How do I continue with testing while another thread waits for "Alert Box" appear event?
Cheers!