【发布时间】:2021-08-25 01:34:25
【问题描述】:
我从另一位开发人员(不再参与该项目)那里获得的一些代码遇到了 UI 测试问题。当出现错误并且我无法让我的 UI 测试看到其中的 UILabel 时,代码会在屏幕顶部显示一个简单的警告框。
盒子的结构是这样的:
UIView
+ UILabel
+ UIButton
在UIView 的自定义类中有这样的代码:
// Original code
accessibilityIdentifier = "AlertBar" // Required for UI Testing.
// Bits I've added trying to make messageLabel visible to UI Test
isAccessibilityElement = true
accessibilityElements = [messageLabel]
messageLabel.accessibilityIdentifier = "AlertBarMessage"
messageLabel.isAccessibilityElement = true
}
如果我在 UI 测试中间断点并将应用转储到日志中,我可以看到 UIView:
Attributes: Application, pid: 60317, label: 'The App'
Element subtree:
→Application, 0x600001df8c40, pid: 60317, label: 'The App'
Window (Main), 0x600001dfa060, {{0.0, 0.0}, {390.0, 844.0}}
... app ui logged here!
Other, 0x600001dce220, {{4.0, 47.0}, {382.0, 107.7}}, identifier: 'AlertBar'
所以很明显,警报对 XCTest 是可见的,但里面什么也没有。从我添加的代码中可以看出,我一直在尝试各种事情,但到目前为止,我还无法使 UILabel (AlertBarMessage) 可见。
我错过了什么?
【问题讨论】: