【问题标题】:iOS UI Testing cannot see the UILabeliOS UI 测试看不到 UILabel
【发布时间】: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) 可见。

我错过了什么?

【问题讨论】:

    标签: xctest xcode-ui-testing


    【解决方案1】:

    像往常一样,在输入 stackOVerFlow 问题后,我返回代码并找出问题所在 :-) 在这种情况下,它是视图上的 isAccessibilityElement = true。使其可访问有效地隐藏了嵌套的UILabel,因此将其关闭修复了我的测试。

    我知道辅助功能中有一些方法可以正确设置视图以实现辅助功能,以便屏幕阅读器将其视为单个元素并可以阅读消息,但我必须稍后再处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-26
      • 1970-01-01
      • 2018-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多