How to check multiple XCTestExpectations using a predicate checking hittable attribute in XCTest
Using the class XCTest XCTWaiter
, I would like to check for predicate
, namely:
NSPredicate(format: "hittable == true")
pending XCTNSPredicateExpectation in open
class func wait(for expectations: [XCTestExpectation], timeout seconds: TimeInterval, enforceOrder enforceOrderOfFulfillment: Bool) -> XCTWaiterResult`
I would like to test this predicate against multiple XCTest Expectation. I think this is the most efficient way to check that multiple items are not allowed on a specific screen.
I found that the combination of using the hittable predicate on an array with more than one wait results in an error
`Assertion Failure: <unknown>:0: Neither attributes nor error returned`
If I use the existence predicate, the expectation array validation wait(for:timeout:enforceOrder:)
works well. Also, if the wait array contains only one wait, the check works fine when combined with the hittable predicate
.
Here is a test method that shows the problem, if you run it in an XCTestCase subclass , you need to set ids to something in your application that is simultaneously displayed on the screen:
func testAssertThatMultipleElementsAreHittable() {
let accessibilityIdentifiers = ["lapTimer", "eventTimer", "startButton", "stopButton"]
let predicate = NSPredicate(format: "hittable == true") //fails with hittable, but passes with exists!
var expectations = [XCTNSPredicateExpectation]()
accessibilityIdentifiers.forEach { (identifier) in
expectations.append(XCTNSPredicateExpectation(predicate: predicate, object: XCUIApplication().descendants(matching: .any)[identifier]))
}
let result = XCTWaiter.wait(for: expectations, timeout: 5.0, enforceOrder: false)
if result != .completed {
XCTFail("waiting failed!")
}
}
Do you have any idea what's going on here?
source to share
No one has answered this question yet
Check out similar questions: