简体   繁体   English

使用NSPredicate在XCUITest中的单元格中搜索

[英]Using NSPredicate to search within Cells in XCUITest

Ive been using XCUITest to perform some UI Automation. 我一直在使用XCUITest执行一些UI自动化。 I have a collection of cells on a page, and want to return the ones that contain a label 我在页面上有一个单元格集合,并想返回包含标签的单元格

Setting a breakpoint and typing in 设置断点并输入

po app.cells

returns 回报

Output: {
      Cell 0x6080003603c0: traits: 8589934592, {{162.9, 184.6}, {916.5, 83.6}},  label: 'reminder same title, description, 4.38 pm'
      Cell 0x618000179380: traits: 8589934592, {{162.9, 268.2}, {916.5, 10.9}}
      Cell 0x608000360300: traits: 8589934592, {{162.9, 279.1}, {916.5, 83.6}},  label: 'reminder same title, description different, 11.37 am'
      Cell 0x618000179440: traits: 8589934592, {{162.9, 362.7}, {916.5, 10.9}}
      Cell 0x600000363a80: traits: 8589934592, {{162.9, 373.6}, {916.5, 83.6}}, label: 'reminder same title, other description, 11.03 am'
      Cell 0x608000360180: traits: 8589934592, {{162.9, 457.2}, {916.5, 10.9}}
      Cell 0x618000179500: traits: 8589934592, {{162.9, 468.0}, {916.5, 83.6}}, label: 'name A, second, 11.00 am'
      Cell 0x618000179740: traits: 8589934592, {{162.9, 551.7}, {916.5, 10.9}}
      Cell 0x610000177580: traits: 8589934592, {{162.9, 562.5}, {916.5, 83.6}}, label: 'name A, first, 11.00 am'
      Cell 0x600000363000: traits: 8589934592, {{162.9, 646.1}, {916.5, 10.9}}
      Cell 0x618000179d40: traits: 8589934592, {{409.4, 362.2}, {293.2, 27.1}}
      Cell 0x600000364800: traits: 8589934592, {{409.4, 389.3}, {293.2, 27.1}}

I understand that an easier way would be to have accessibility identifiers associated with the Cells that have labels, but Im unsure of how to structure a NSPredicate query in order to probe the Cells collection and only return the Cells containing a label. 我知道一种更简单的方法是让具有标签的单元格与可访问性标识符相关联,但是我不确定如何构造NSPredicate查询以探测单元格集合并仅返回包含标签的单元格。

This should give you all the cells whose label is not nil 这应该给您所有标签不为零的单元格

let predicate = NSPredicate(format: "label != nil")
let cells = XCUIApplication().cells.matching(predicate)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM