UITableView的可访问性不起作用

时间:2016-04-21 09:17:40

标签: ios xcode uitableview xcode-ui-testing uiaccessibility

我在XCode / Swift中为应用程序编写了一些UITests。在这个应用程序中,我有一个UITableView与一些单元格(当然),但对于测试,这个tableview表现就像它是空的。

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

我已经添加了辅助功能标识符,但它仍然是空的,您可以在此日志中看到。

↪︎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"是包含UITableView的视图的标识符,因为您可以看到表视图本身存在,但之后没有任何内容。有人知道应该怎么做才能解决这个问题吗?

提前致谢:)

PS 我使用了XCode辅助功能检查器,结果基本相同

Accessibility inspector results when hovering over the table

3 个答案:

答案 0 :(得分:0)

您可以尝试.Cell类型的后代 像这样的东西 -

XCUIApplication().descendantsMatchingType(.Any).matchingIdentifier("HelpContainer").tables.descendantsMatchingType(.Cell)

答案 1 :(得分:0)

我还没有多少运气直接在UI测试中查询表格单元格。相反,我将通过它包含的文本标签访问元素。

例如,如果您有一张包含iPhone列表的表格,我会点击iPhone 5的单元格。

let app = XCUIApplication()
app.staticTexts["iPhone 5"].tap()

答案 2 :(得分:0)

不久前我自己也遇到了这个问题。

在某种程度上它是非常反直觉的,但容器本身不应该是UIAccessibilityEnabled = TRUE对象。确保tableview本身不是UI Accessibility元素,并且tableview中的单元格是。