【问题标题】:Swift UI Test fails on iphone4s simulator works well with othersiphone4s 模拟器上的 Swift UI 测试失败与其他模拟器配合得很好
【发布时间】:2015-12-23 17:37:12
【问题描述】:

我的应用中有一个登录屏幕,然后在登录视图被关闭后会出现一个标签栏。

应用程序本身在所有设备/模拟器中运行良好。 UI 测试适用于除 iphone 4s 之外的所有模拟器。

我认为原因是登录后,登录屏幕消失的时间太长了。所以当我尝试访问标签栏时,它会引发异常。

我试过了

let tabBarsQuery = app.tabBars
let predicate = NSPredicate(format: "exists == true")
expectationForPredicate(predicate, evaluatedWithObject: tabBarsQuery, handler: nil)
waitForExpectationsWithTimeout(15, handler: nil) 

我收到以下错误

failed: caught "NSUnknownKeyException", "[<XCUIElementQuery 0x7e080d40> valueForUndefinedKey:]: this class is not key value coding-compliant for the key exists."

为什么期望不起作用?我怎么解决这个问题?

【问题讨论】:

  • 您用于测试的所有设备是否都具有完全相同的 iOS 固件?
  • 我将所有模拟器设置为 9.2,现在所有模拟器都在发生这种情况。
  • 当我删除 predicate 时,它适用于除 4s 之外的所有人

标签: ios iphone swift ui-testing nsunknownkeyexception


【解决方案1】:

所以这个问题似乎是无论出于何种原因,XCUIElementQueries 集合都不存在 .exists 属性。在您的示例中,您不能执行app.tabBars.exists。但是,您可以将谓词更改为:

let predicate = NSPredicate(format: "count > 0")

这应该可行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 2010-10-10
    • 2021-12-25
    • 2020-01-05
    • 1970-01-01
    相关资源
    最近更新 更多