Get an element containing another element with static text in iOS UITesting

How to build a query to get an element containing another element using static text.

Example: get the first cell of the table containing the label with the text "cool cell"

I need this because I have different cells, and I want to get a cell containing specific text. Note that I'm interested in getting a cell, because I need to make sure that the cell contains other elements. The goal is to make sure that the cell named "I cell" also has a label with the text "cool"

+5
source share
3 answers

If you are interested in testing Perhaps this library can help you.

+1
source

Get the first cell of the table containing the label with the text "cool cell"

What about:

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

If this is not enough, there is a containing version that accepts NSPredicate :

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

Documentation:

Returns a new query to search for elements that contain a child that matches the specification that you need. [...]

+1
source

If you don't want to use external libraries, there is something that blocks you by adding a new user interface testing goal and introducing a testing class in which you create a dummy data source and simply initialize an array of cells (made from nibs) and then check them there ?

0
source

Source: https://habr.com/ru/post/1275401/


All Articles