【发布时间】: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