【发布时间】:2020-04-03 08:53:24
【问题描述】:
我想为 UIStackView 内的视图编写 UI 测试,即 MKMapView 内的视图。
这是MWE的sn-p。我创建了一个 MKMapView 添加了一个 UIStackView 和两个 UIViews 作为子视图。
let map = MKMapView()
let view1 = UIView()
let view2 = UIView()
let stackView = UIStackView()
stackView.addArrangedSubview(view1)
stackView.addArrangedSubview(view2)
map.addSubview(stackView)
view.addSubview(map)
我为每个元素声明了一个accessibilityIdentifier 并将isAccessibilityElement 属性设置为true。
view1.accessibilityIdentifier = "view1"
view2.accessibilityIdentifier = "view2"
stackView.accessibilityIdentifier = "stackView"
view1.isAccessibilityElement = true
view2.isAccessibilityElement = true
stackView.isAccessibilityElement = true
但是,在应用程序元素子树中没有可见的堆栈视图的子视图,也无法访问它们。
您可以看到带有标识符“stackView”的UIStackView,但看不到UIViews。
Element subtree:
→Application, 0x6000030080e0, pid: 11856, label: 'UITestWithStackView'
Window (Main), 0x600003009500, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003009420, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003009340, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003009260, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003009180, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x6000030090a0, {{7.0, 348.0}, {400.0, 200.0}}, identifier: 'stackView'
Other, 0x600003008fc0, {{0.0, 0.0}, {414.0, 896.0}}
Map, 0x600003008ee0, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003008e00, {{0.0, 0.0}, {414.0, 896.0}}
Link, 0x600003008d20, {{375.4, 841.3}, {28.6, 10.7}}, label: 'Legal'
Window, 0x600003008c40, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003008b60, {{0.0, 0.0}, {414.0, 896.0}}
Other, 0x600003008a80, {{0.0, 0.0}, {414.0, 896.0}}
对于这种行为是否有任何已知的解决方法?
【问题讨论】:
-
我也遇到了这个奇怪的问题。非常令人沮丧。
标签: ios swift xcode testing uitest