0

How to write a UI Test (XCTestCase) that waits for a UISwitch to be enabled.

I added this code to one of my tests but it timed out:

let firstSwitch = XCUIApplication().switches.elementBoundByIndex(0)
_ = self.expectationForPredicate(
  NSPredicate(format: "self.value = %@", enabled),
  evaluatedWithObject: firstSwitch,
  handler: nil)
self.waitForExpectationsWithTimeout(15.0, handler: nil)
izik lisbon
  • 121
  • 2
  • 4

1 Answers1

0

Just replace self.value with self.value.boolValue:

let firstSwitch = XCUIApplication().switches.elementBoundByIndex(0)
_ = self.expectationForPredicate(
  NSPredicate(format: "self.value.boolValue = %@", enabled),
  evaluatedWithObject: firstSwitch,
  handler: nil)
self.waitForExpectationsWithTimeout(15.0, handler: nil)
izik lisbon
  • 121
  • 2
  • 4