在 Xcode UI 测试中,如何测试 staticTexts 是否包含字符串?
在调试器中,我可以运行类似的命令来打印出 staticTexts 的所有内容:po app.staticTexts
。但是如何测试所有内容中的任何位置是否存在字符串?
我可以检查每个 staticText 是否存在,执行类似的操作app.staticTexts["the content of the staticText"].exists
?但我必须使用该静态文本的确切内容。如何仅使用可能只是该内容的一部分的字符串?
您可以使用NSPredicate
来过滤元素。
let searchText = "the content of the staticText"
let predicate = NSPredicate(format: "label CONTAINS[c] %@", searchText)
let elementQuery = app.staticTexts.containing(predicate)
if elementQuery.count > 0 {
// the element exists
}
With CONTAINS[c]
您指定搜索不区分大小写。
看看苹果谓词编程指南 https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/AdditionalChapters/Introduction.html#//apple_ref/doc/uid/TP40001789
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)