0

I'm writing some UITests in XCode/Swift for an app. In this app I have a UITableView with some cells (off course) but for the tests, this tableview behaves as if it was empty.

print(XCUIApplication().descendantsMatchingType(.Any).matchingIdentifier("HelpContainer").tables.descendantsMatchingType(.Any).debugDescription)

I already added the accessibility identifiers but it's still empty as you can see in this log.

↪︎Find: Descendants matching type Any
Output: {
  Image 0x7fd33c127630: traits: 8589934596, {{0.0, 64.0}, {375.0, 1.0}}
  Image 0x7fd33ac37890: traits: 8589934596, {{0.0, 0.0}, {375.0, 64.0}}
  Button 0x7fd33c40b780: traits: 8589934593, {{8.0, 26.0}, {54.0, 30.0}}, label: 'Cancel'
  Button 0x7fd33c143b80: traits: 8724152321, {{8.0, 31.5}, {21.0, 21.0}}, label: 'Back'
  StaticText 0x7fd33c1e67c0: traits: 8590000192, {{168.5, 29.0}, {38.5, 27.0}}, label: 'Help'
  NavigationBar 0x7fd33ac0fd30: traits: 35192962023424, {{0.0, 20.0}, {375.0, 44.0}}, identifier: 'Help'
  Other 0x7fd33ac39370: traits: 8589934592
  Table 0x7fd33c144b00: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fd33c1e7570: traits: 8589934592
  Other 0x7fd33ac38b40: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}, identifier: 'HelpContainer'
  Other 0x7fd33ac383c0: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fd33ac37c40: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fd33ac26240: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fd33ac25fb0: {{0.0, 0.0}, {375.0, 667.0}}
  Window 0x7fd33ac2bdb0: Main Window, {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fd33ac39b30: traits: 8589934592
  Other 0x7fd33c1e6f80: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
  Window 0x7fd33c1e78c0: {{0.0, 0.0}, {375.0, 667.0}}
  Other 0x7fd33ac3b1b0: {{0.0, 0.0}, {375.0, 20.0}}
  Other 0x7fd33c1450a0: traits: 8388608, {{6.0, 0.0}, {54.0, 20.0}}
  Other 0x7fd33c121790: traits: 8388608, {{65.0, 0.0}, {13.0, 20.0}}, label: '3 of 3 Wi-Fi bars', value: SSID
  Other 0x7fd33ac3b4d0: traits: 8389120, {{163.0, 0.0}, {52.0, 20.0}}, label: '11:12 AM'
  Other 0x7fd33ac3bc60: traits: 8388608, {{345.0, 0.0}, {25.0, 20.0}}, label: '-100 % battery power'
  Other 0x7fd33ad671b0: {{0.0, 0.0}, {375.0, 20.0}}
  StatusBar 0x7fd33ac3aa40: {{0.0, 0.0}, {375.0, 20.0}}
  Window 0x7fd33ac3a2c0: {{0.0, 0.0}, {375.0, 667.0}}
}
↪︎Find: Elements matching predicate '"HelpContainer" IN identifiers'
  Output: {
    Other 0x7fd33ac38b40: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}, identifier: 'HelpContainer'
  }
  ↪︎Find: Descendants matching type Table
    Output: {
      Table 0x7fd33c144b00: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
    }
    ↪︎Find: Descendants matching type Any

"HelpContainer" is the identifier of the view that contains the UITableView, as you can see the table view itself is there but afterwards, nothing. Does anybody knows what should be done to fix this?

Thanks in advance :)

PS I used XCode accessibility inspector and the result was basically the same

Accessibility inspector results when hovering over the table

mtet88
  • 524
  • 6
  • 21

3 Answers3

0

You can try with descendants of type .Cell Something like this -

XCUIApplication().descendantsMatchingType(.Any).matchingIdentifier("HelpContainer").tables.descendantsMatchingType(.Cell)
reamd
  • 41
  • 5
  • I did this... print(XCUIApplication().descendantsMatchingType(.Any).matchingIdentifier("HelpContainer").tables.descendantsMatchingType(.Cell).count) and the result is 0, even though there are 3 cells :( – mtet88 Apr 21 '16 at 10:57
0

I haven't had much luck querying for table cells directly in UI Testing. Instead, I will access the element by the text label it contains.

For example, if you have a table with a list of iPhones I would tap the iPhone 5's cell with the following.

let app = XCUIApplication()
app.staticTexts["iPhone 5"].tap()
Joe Masilotti
  • 16,815
  • 6
  • 77
  • 87
  • Tried to do that but the query has no results either – mtet88 Apr 21 '16 at 13:05
  • Are you using custom cells? If so, what kind of UI elements are the subviews? – Joe Masilotti Apr 21 '16 at 16:18
  • Yes, they are custom cells with 3 UILabels inside. I even put accessibility identifier to the cell and to each of the labels, made a query using the identifiers and even using the text in the labels but the query doesn't find anything below the table (in the structure) like if the table was empty – mtet88 Apr 21 '16 at 16:37
0

Ran into this problem myself a little while ago.

It's very counter-intuitive in a way, but containers should not themselves be UIAccessibilityEnabled = TRUE objects. Make sure that the tableview itself is NOT a UI Accessibility element, and that the cells within the tableview are.

Aaron Sofaer
  • 706
  • 4
  • 19