Swift2 UI Test - Wait for Element to Appear

前端 未结 6 1129
逝去的感伤
逝去的感伤 2021-02-13 15:40

I want to have a test pause and wait for an element to appear on screen before proceeding.

I don\'t see a good way to create an expectation for this and wait using

6条回答
  •  梦毁少年i
    2021-02-13 16:16

    You can use this, in Swift 3

    func wait(element: XCUIElement, duration: TimeInterval) {
      let predicate = NSPredicate(format: "exists == true")
      let _ = expectation(for: predicate, evaluatedWith: element, handler: nil)
    
      // We use a buffer here to avoid flakiness with Timer on CI
      waitForExpectations(timeout: duration + 0.5)
    }
    

    In Xcode 9, iOS 11, you can use the new API waitForExistence

提交回复
热议问题