Swift2 UI Test - Wait for Element to Appear

前端 未结 6 1137
逝去的感伤
逝去的感伤 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条回答
  •  失恋的感觉
    2021-02-13 16:31

    For Xcode 8.3 and later you can wait for expectation with a new class - XCTWaiter, an example test looks like this:

    func testExample() {
      let element = // ...
      let predicate = NSPredicate(format: "exists == true")
      let expectation = XCTNSPredicateExpectation(predicate: predicate, object: element)
    
      let result = XCTWaiter().wait(for: [expectation], timeout: 1)
      XCTAssertEqual(.completed, result)
    }
    

    Read the documentation for more information.

提交回复
热议问题