有没有办法在UITest中将valueForKey与NSPredicate一起使用?

线粒体

我的iOS UI测试具有以下测试助手功能:

func waitForElementToHaveKeyboardFocus(element: XCUIElement) {
    self.expectationForPredicate(NSPredicate(format:"valueForKey(\"hasKeyboardFocus\") == true"), evaluatedWithObject:element, handler: nil)
    self.waitForExpectationsWithTimeout(5, handler: nil)
}

在我的测试中,我有:

let usernameTextField = app.textFields["Username"]
let passwordTextField = app.secureTextFields["Password"]
waitForElementToHaveKeyboardFocus(usernameTextField)

测试失败,并出现以下错误:

error: -[ExampleAppUITests.ExampleAppUITests testExampleApp] : failed: caught "NSUnknownKeyException", "[<_NSPredicateUtilities 0x10e554ee8> valueForUndefinedKey:]: this class is not key value coding-compliant for the key hasKeyboardFocus."

如果我在测试失败时在测试中设置一个断点,然后手动调用valueForKey("hasKeyboardFocus")焦点和非焦点字段,那么我似乎会得到正确的行为:

(lldb) po usernameTextField.valueForKey("hasKeyboardFocus")
    t =    51.99s     Find the "Username" TextField
    t =    51.99s         Use cached accessibility hierarchy for ExampleApp
    t =    52.00s         Find: Descendants matching type TextField
    t =    52.01s         Find: Elements matching predicate '"Username" IN identifiers'
▿ Optional<AnyObject>
  - Some : 1

(lldb) po passwordTextField.valueForKey("hasKeyboardFocus")
    t =   569.99s     Find the "Password" SecureTextField
    t =   569.99s         Use cached accessibility hierarchy for ExampleApp
    t =   570.01s         Find: Descendants matching type SecureTextField
    t =   570.01s         Find: Elements matching predicate '"Password" IN identifiers'
▿ Optional<AnyObject>
  - Some : 0

是否有可能做valueForKey一个XCUIElement工作,NSPredicate在UI测试?还有另一种优雅的方法可以做到这一点吗?

乔·马西洛蒂(Joe Masilotti)

看来您的谓词略有偏离。尝试将其更改为以下内容:

NSPredicate(format: "hasKeyboardFocus == true"), evaluatedWithObject:element, handler: nil)

valueForKey创建谓词时,您无需传递零件。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

有没有办法将QTcpSocket与现有套接字一起使用?

来自分类Dev

有没有办法与工头一起使用Figaro?

来自分类Dev

有没有办法将Java集合与扩展类类型一起使用?

来自分类Dev

有没有办法将PredicateBuilder与Azure表存储一起使用?

来自分类Dev

有没有办法将OpenCV中的minAreaRect与double一起使用?

来自分类Dev

有没有办法将Storyboard与ListView / GridView项一起使用?

来自分类Dev

有没有办法将运动与寄存器一起使用?

来自分类Dev

有没有办法将`set_index`与方法链接一起使用?

来自分类Dev

有没有办法将密钥文件与TrueCrypt全盘加密一起使用?

来自分类Dev

有没有办法让Kindle Fire与12.04一起使用?

来自分类Dev

有没有办法将ScheduledExecutorService与ExecutorCompletionService一起使用?

来自分类Dev

有没有办法将rand()与变量一起使用?

来自分类Dev

有没有办法将rxjs与ng2-charts一起使用?

来自分类Dev

有没有办法让石墨烯与 django GenericRelation 字段一起使用?

来自分类Dev

有没有办法设置一个与 aiortc 一起使用的全局变量?

来自分类Dev

有没有办法将Solr的流式API与spring数据solr一起使用?

来自分类Dev

有没有办法将Bootstrap 3.0插件与jQuery.noConflict()一起使用?

来自分类Dev

有没有办法让Tapply与两个索引值(或等效值)一起使用?

来自分类Dev

有没有办法将Redux动作和reducer与react-final-form一起使用?

来自分类Dev

有没有办法将本地tf Attention层与keras Sequential API一起使用?

来自分类Dev

有没有办法让VirtualBox与Intel 64位处理器一起使用?

来自分类Dev

有没有办法让Tapply与两个索引值(或等效值)一起使用?

来自分类Dev

有没有办法将复选框与Nullable Bool属性一起使用

来自分类Dev

有没有办法将protobuf-csharp-port生成的类与servicestack.ormlite一起使用?

来自分类Dev

有没有办法将通配符,重定向或其他shell语法与systemd单元一起使用?

来自分类Dev

C# 有没有办法将 DllImport 与泛型方法类型一起使用?

来自分类Dev

有没有办法将输入连接在一起?

来自分类Dev

有没有办法“逆转” NSPredicate

来自分类Dev

有没有办法在Google脚本中将arrayformula与match / index一起使用?或者至少可以自动填充整个列?脚本是一种选择

Related 相关文章

  1. 1

    有没有办法将QTcpSocket与现有套接字一起使用?

  2. 2

    有没有办法与工头一起使用Figaro?

  3. 3

    有没有办法将Java集合与扩展类类型一起使用?

  4. 4

    有没有办法将PredicateBuilder与Azure表存储一起使用?

  5. 5

    有没有办法将OpenCV中的minAreaRect与double一起使用?

  6. 6

    有没有办法将Storyboard与ListView / GridView项一起使用?

  7. 7

    有没有办法将运动与寄存器一起使用?

  8. 8

    有没有办法将`set_index`与方法链接一起使用?

  9. 9

    有没有办法将密钥文件与TrueCrypt全盘加密一起使用?

  10. 10

    有没有办法让Kindle Fire与12.04一起使用?

  11. 11

    有没有办法将ScheduledExecutorService与ExecutorCompletionService一起使用?

  12. 12

    有没有办法将rand()与变量一起使用?

  13. 13

    有没有办法将rxjs与ng2-charts一起使用?

  14. 14

    有没有办法让石墨烯与 django GenericRelation 字段一起使用?

  15. 15

    有没有办法设置一个与 aiortc 一起使用的全局变量?

  16. 16

    有没有办法将Solr的流式API与spring数据solr一起使用?

  17. 17

    有没有办法将Bootstrap 3.0插件与jQuery.noConflict()一起使用?

  18. 18

    有没有办法让Tapply与两个索引值(或等效值)一起使用?

  19. 19

    有没有办法将Redux动作和reducer与react-final-form一起使用?

  20. 20

    有没有办法将本地tf Attention层与keras Sequential API一起使用?

  21. 21

    有没有办法让VirtualBox与Intel 64位处理器一起使用?

  22. 22

    有没有办法让Tapply与两个索引值(或等效值)一起使用?

  23. 23

    有没有办法将复选框与Nullable Bool属性一起使用

  24. 24

    有没有办法将protobuf-csharp-port生成的类与servicestack.ormlite一起使用?

  25. 25

    有没有办法将通配符,重定向或其他shell语法与systemd单元一起使用?

  26. 26

    C# 有没有办法将 DllImport 与泛型方法类型一起使用?

  27. 27

    有没有办法将输入连接在一起?

  28. 28

    有没有办法“逆转” NSPredicate

  29. 29

    有没有办法在Google脚本中将arrayformula与match / index一起使用?或者至少可以自动填充整个列?脚本是一种选择

热门标签

归档