简体   繁体   中英

Get an element that contains another element with a static text in iOS UITesting

How to build a query to get an element that contains another element by static text.

Example: Get the first table cell that contains a label with text "cool cell"

I need it because I have different cells and I want to get a cell that contains a specific text. Note that I'm interested to get the cell because I need to make sure that the cell contains another elements. The goal is to make sure that the cell with the title "I'm a cell" has also a label with text "cool"

如果您对测试感兴趣,也许这个库可以帮助您。

Get the first table cell that contains a label with text "cool cell"

How about:

let app = XCUIApplication()
app.cells.containing(.staticText, identifier: "cool cell")

If that's not enough, there's a version of containing that takes NSPredicate :

func containing(_ predicate: NSPredicate) -> XCUIElementQuery
func containing(_ elementType: XCUIElement.ElementType, identifier: String?) -> XCUIElementQuery

Documentation:

Returns a new query for finding elements that contain a descendant matching the specification" which is what you need. [...]

如果您不想使用外部库,那么有什么阻止您形成添加新的UI测试目标并实现测试类,您可以在其中创建虚拟数据源并初始化单元格数组(由nibs构成)然后验证它们那里?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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