如果预期元素(在我的情况下为警报)在超时之前没有出现(根据服务器请求),我有一个任务要成功通过 UITest。
代码:
let element = app.alerts["test text"]
let existsPredicate = NSPredicate(format: "exists == true")
expectation(for: existsPredicate, evaluatedWith: element, handler: nil)
waitForExpectations(timeout: 10, handler: nil)
// when timeout expired test should finish with success
未通过互联网找到任何解决方案。
最佳答案
Оооо,你应该注意它是UITest
。在这种情况下,期望有一个很好的属性:isInverted
。将其设置为 true 表示预期不会发生。 )))
let element = app.alerts["test text"]
let existsPredicate = NSPredicate(format: "exists == true")
let expectation = expectation(for: existsPredicate, evaluatedWith: element, handler: nil)
expectation.isInverted = true // if alert doesn't appear during 10 seconds, then test passed
waitForExpectations(timeout: 10, handler: nil)
关于ios - 当 waitForExpectations 失败时,在 UITest 上获得成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47384475/