如何将期望与 XCUIElementQuery UISwitch 一起使用 expectationForPredicat



如何编写等待UISwitch启用的UI测试(XCTestCase)。

我将此代码添加到我的一个测试中,但它超时了:

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

只需将self.value替换为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)

最新更新