How can I change the time required to get a snapshot in Xcode UI Test (XCUITest)?

帅比萌擦擦* 提交于 2019-12-05 12:29:57

You can use expectations to allocate an arbitrary amount of time to run any test case. You just create an additional expectation right before 15.0s has passed, and repeat this process as many times as necessary. Here's a short code sample to illustrate:

var timeToDelay = 60.0
repeat {
    let delay = min(13.0, timeToDelay)
    timeToDelay -= delay
    let date = Date().addingTimeInterval(delay)
    let predicate = NSPredicate(format: "now() > %@", argumentArray: [date])
    self.expectation(for: predicate, evaluatedWith: [], handler: nil)
    self.waitForExpectations(timeout: 14.0, handler: nil)
} while timeToDelay > 0

Place this right before you see the testing failure and replace timeToDelay with the amount of additional time you need (in seconds).

I don't think this is possible. Apple has a system limit of 20 seconds for any app to start up, if it takes longer than that your app will be killed. Source

Because UI tests require bootstrapping your app, Apple has given itself ~5 seconds to perform all of it's setup as well. So essentially you have a 15 second limit to launch your app.

Because it's not possible to override the system's 20 second limit, it's also not going to be possible to override XCTest's 15 second limit.

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