Swift2 UI Test - Wait for Element to Appear

前端 未结 6 1136
逝去的感伤
逝去的感伤 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:09

    In expectationForPredicate(predicate: evaluatedWithObject: handler:) you don't give an actual object, but a query to find it in the view hierarchy. So, for example, this is a valid test:

    let predicate = NSPredicate(format: "exists == 1")
    let query = XCUIApplication().buttons["Button"]
    expectationForPredicate(predicate, evaluatedWithObject: query, handler: nil)
    
    waitForExpectationsWithTimeout(3, handler: nil)
    

    Check out UI Testing Cheat Sheet and documentation generated from the headers (there is no official documentation at the moment), all by Joe Masilotti.

提交回复
热议问题