ios - XCTest waitForExpectations(...) 等待多个结果

标签 ios xctest xcode-ui-testing ui-testing

在 UITest 中,点击登录按钮后,我需要等待两个事件,登录成功后是否显示更新或主屏幕,然后决定要做什么。 文档说,

Only one -waitForExpectationsWithTimeout:handler: can be active at any given time, but * multiple discrete sequences of { expectations -> wait } can be chained together.

所以需要稍微解决一下,但终于想通了。

最佳答案

您可以向谓词添加参数并在条件之间使用 OR。

let skipUpdateButtonPredicate = NSPredicate(format: "%@.exists == 1 OR %@.exists == 1", skipUpdateButton, homeTabBar)
self.expectation(for: skipUpdateButtonPredicate, evaluatedWith: [Any](), handler: nil)
testCase.waitForExpectations(timeout: Constants.loginTimeout,
                                 handler: nil)

然后你可以在这里分支,如果 home 或 update 出现了:

if skipUpdateButton.exists {
    skipUpdateButton.tap()
}

关于ios - XCTest waitForExpectations(...) 等待多个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42957890/

相关文章:

ios - 在 Xcode UI 测试中等待 30 秒

ios - 在设备上运行 UI 测试 xcode 7

ios - 切换到 Swift 4 后 BarButtonItem 格式错误

ios - Facebook 注册

iphone - 应用内购买和应用拒绝 iOS

ios - Xcode Scheme 默认位置在测试中被忽略

javascript - 输入后滚动Phonegap iOS

swift - 使用或不使用主机应用程序对自定义 iOS 框架进行单元测试

ios - 我们需要为登录编写 UI 测试用例吗?

ios - Xcode UI 测试导致每台 iOS 设备崩溃