【问题标题】:XCUIElement hierarchy within UITableViewCellUITableViewCell 中的 XCUIElement 层次结构
【发布时间】:2018-08-23 08:25:58
【问题描述】:

我在 UI 测试中遇到了一个奇怪的行为。 当我将自定义视图添加到 UITableViewCell 中时,它的某些子视图无法访问。 但是,在 Xcode 的 Debug View Hierarchy 中是可以的。

是的,我知道 UIAccessibilityContainer 但这不是解决方案的原因: 1.我的自定义视图(视图、标签、图像)中有常规的子视图,而不是绘制的内容。 2. 我无法为 containerView 禁用 isAccessibilityElement 并为 ImageView 启用它,因为我同时需要两者。

因此,当我将视图按原样添加到 TableViewCell 时,我只能从 UI 测试中访问少数元素:

Table, 0x604000196da0, traits: 35192962023424, {{5.0, 108.0}, {404.0, 586.0}}
  Cell, 0x604000384b90, traits: 8589934592, {{5.0, 132.0}, {365.0, 329.0}}
    StaticText, 0x6040003849f0, traits: 8589934656, {{9.0, 135.7}, {25.0, 12.7}}, identifier: 'myLabel', label: '123'
    StaticText, 0x604000384780, traits: 8589934656, {{73.0, 154.3}, {293.0, 18.7}}, identifier: 'titleLabel', label: 'Title'

如果我为图像启用 isAccessibilityElement,我也可以看到它:

Table, 0x604000196da0, traits: 35192962023424, {{5.0, 108.0}, {404.0, 586.0}}
  Cell, 0x604000384b90, traits: 8589934592, {{5.0, 132.0}, {365.0, 329.0}}
    Image, 0x604000384ac0, traits: 8589934596, {{9.0, 235.7}, {357.0, 174.3}}, identifier: 'myImage'
    StaticText, 0x6040003849f0, traits: 8589934656, {{9.0, 135.7}, {25.0, 12.7}}, identifier: 'myLabel', label: '123'
    StaticText, 0x604000384780, traits: 8589934656, {{73.0, 154.3}, {293.0, 18.7}}, identifier: 'titleLabel', label: 'Title'
    Image, 0x604000384370, traits: 8589934596, {{9.0, 156.3}, {56.0, 56.0}}, identifier: 'myIcon'

但是,在这两种情况下,Cell 中的层次结构都很简单,并且没有容器视图。

【问题讨论】:

    标签: ios xcode-ui-testing uiaccessibility


    【解决方案1】:

    解决办法是:用 UICollectionView 代替 UITableView。

    这是一个正确的层次结构(isAccessibilityElement 对每个元素都有默认值)。

    Other, 0x600000193590, traits: 8589934592, {{5.0, 132.0}, {365.0, 604.0}}
      CollectionView, 0x6000001930b0, traits: 35192962023424, {{5.0, 132.0}, {365.0, 573.0}}
        Cell, 0x600000192fe0, traits: 8589934592, {{5.0, 132.0}, {365.0, 329.0}}
          Other, 0x600000192f10, traits: 8589934592, {{5.0, 132.0}, {365.0, 329.0}}
            Other, 0x6040001900c0, traits: 8589934592, {{0.0, 129.7}, {375.0, 333.7}}, identifier: 'myView'
              Other, 0x604000192e40, traits: 8589934592, {{0.0, 129.7}, {375.0, 333.9}}, identifier: 'contentView'
                StaticText, 0x60400018f970, traits: 8589934656, {{4.0, 133.7}, {25.0, 12.7}}, identifier: 'myLabel', label: '123'
                Image, 0x60400018fd80, traits: 8589934596, {{4.0, 154.3}, {56.0, 56.0}}, identifier: 'myIcon'
                StaticText, 0x60400018f7d0, traits: 8589934656, {{68.0, 152.3}, {303.0, 18.7}}, identifier: 'titleLabel', label: 'Title'
                Other, 0x60400018ee10, traits: 8589934592, {{4.0, 233.7}, {367.0, 179.2}}, identifier: 'containerView'
                  Image, 0x60400018eba0, traits: 8589934596, {{4.0, 233.7}, {367.0, 179.2}}, identifier: 'myImage'
    

    【讨论】:

      猜你喜欢
      • 2016-01-23
      • 2012-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-09
      相关资源
      最近更新 更多