ios - 当 waitForExpectations 失败时,在 UITest 上获得成功

标签 ios swift xcode-ui-testing uitest

如果预期元素(在我的情况下为警报)在超时之前没有出现(根据服务器请求),我有一个任务要成功通过 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/

相关文章:

ios - 如何快速刷新 Firebase 推送通知

ios - ATS 将在 IOS 应用程序中强制执行。简单的饲料呢?

ios - Swift 3 中的 Alamofire?

ios - 在应用程序启动时在 iOS 模拟器中获取用户坐标

objective-c - SetFrame 适用于 iPhone,但不适用于 iPad。自动调整蒙版大小是罪魁祸首?

swift - 如何在 swift 中使用 CFDictionarySetValue?

iOS - 本地保存键值对数组

ios - 使用xcode 7进行UITesting

ios - 在 Xcode 7 的 UI 测试中使用 '-[XCUIElement swipeDown]' 时如何设置滑动距离

objective-c - 如何使用 XCUIElementQuery 测试 UIView 是否存在?