【问题标题】:Accesibility for UITableView doesn't work表格视图的辅助功能不起作用
【发布时间】:2016-04-21 09:17:39
【问题描述】:

我正在用 XCode/Swift 为应用程序编写一些 UITest。在这个应用程序中,我有一个带有一些单元格的 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 的视图的标识符,因为您可以看到表格视图本身在那里,但之后什么也没有。有谁知道应该怎么做才能解决这个问题?

提前谢谢:)

附言 我用了XCode辅助检查器,结果基本一样

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 我这样做了... print(XCUIApplication().descendantsMatchingType(.Any).matchingIdentifier("HelpContainer").tables.descendantsMatchingType(.Cell).count) 结果是0,甚至虽然有3个单元格:(
    【解决方案2】:

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

    例如,如果您有一个包含 iPhone 列表的表格,我会点击 iPhone 5 的单元格并显示以下内容。

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

    【讨论】:

    • 试图这样做,但查询也没有结果
    • 您使用的是自定义单元格吗?如果有,子视图是什么类型的 UI 元素?
    • 是的,它们是自定义单元格,里面有 3 个 UILabel。我什至将可访问性标识符放入单元格和每个标签,使用标识符进行查询,甚至使用标签中的文本,但查询在表格下方(在结构中)没有找到任何东西,就像表格一样空
    【解决方案3】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-30
      • 2020-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-07
      • 1970-01-01
      相关资源
      最近更新 更多