Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS UI测试:如何获取元素列表_Ios_Iphone_Xcode_Xctest_Xcode Ui Testing - Fatal编程技术网

iOS UI测试:如何获取元素列表

iOS UI测试:如何获取元素列表,ios,iphone,xcode,xctest,xcode-ui-testing,Ios,Iphone,Xcode,Xctest,Xcode Ui Testing,我正在用XUITest在iOS上进行测试,在一个搜索测试案例中,我想验证所有搜索建议是否以用户输入的字母开头,比如说,如果我输入“p”,搜索建议应该有“ps4”、“phone”、“ps3”等 环顾四周,我觉得大多数元素查询方法都会尝试返回单个元素, 如: let predicate=NSPredicate(格式:“label BEGINSWITH[cd]'p'”) app.buttons.element匹配谓词(谓词) 在某些情况下,匹配相同条件的元素列表也很重要,有什么方法可以实现这一点吗 @

我正在用XUITest在iOS上进行测试,在一个搜索测试案例中,我想验证所有搜索建议是否以用户输入的字母开头,比如说,如果我输入“p”,搜索建议应该有“ps4”、“phone”、“ps3”等

环顾四周,我觉得大多数元素查询方法都会尝试返回单个元素, 如:
let predicate=NSPredicate(格式:“label BEGINSWITH[cd]'p'”)
app.buttons.element匹配谓词(谓词)


在某些情况下,匹配相同条件的元素列表也很重要,有什么方法可以实现这一点吗

@Nieshumi首先看起来这个任务不适合ui。 那么,为什么您不能使用以下函数之一:

 /*! Returns a new query that applies the specified attributes or predicate to the receiver. The predicate will be evaluated against objects of type id<XCUIElementAttributes>. */
open func matching(_ predicate: NSPredicate) -> XCUIElementQuery

open func matching(_ elementType: XCUIElementType, identifier: String?) -> XCUIElementQuery

open func matching(identifier: String) -> XCUIElementQuery


/*! Returns a new query for finding elements that contain a descendant matching the specification. The predicate will be evaluated against objects of type id<XCUIElementAttributes>. */
open func containing(_ predicate: NSPredicate) -> XCUIElementQuery

open func containing(_ elementType: XCUIElementType, identifier: String?) -> XCUIElementQuery

这并不能回答您的问题,但我认为这应该是一个单元测试,而不是UI测试。您正在这里测试功能(搜索字母“p”并返回列表)。UI测试应该只确认在单击“搜索”按钮后显示了标签(或列表)。它不应该太在意它的内容。@Hodson我有点同意你的看法,我一直在为UI测试应该验证多少细节而挣扎
 app.buttons.matching(NSPredicate(format: "label == [cd] %@", myVar)).count>1 ? doSmthWithQuery(): doSmthWithElement()