iOS 9 UI Testing - Test Fails Because Target Control Isn't Available (yet)

家住魔仙堡 提交于 2019-12-03 17:28:45

I would recommend against ticking the run loop and instead use the built in XCTest asynchronous API. For example:

let app = XCUIApplication()
app.launch()

let textField = app.textField["user name"]
let existsPredicate = NSPredicate(format: "exists == 1")

expectationForPredicate(existsPredicate, evaluatedWithObject: textField, handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)

textField.tap()
textField.type("joemasilotti")

This will wait until the text field with accessibility label/identifier "username" actually exists on the screen. Then it will tap on the text field, making it active, and type my username. If five seconds pass before this becomes true the test will fail.

I have also written a post on how to use UI Testing on my blog and put together a UI Testing Cheat Sheet for scenarios like this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!