【发布时间】:2021-07-14 00:22:26
【问题描述】:
使用 Xcode 12.4 模拟器 14.4
对于下面显示的警报,我在 XCUITests 中有以下函数,用于提取系统警报上显示的静态文本:
_ = addUIInterruptionMonitor(withDescription: "", handler: { (alert) -> Bool in
var data = alert.staticTexts.allElementsBoundByIndex.map {$0.label}
...
})
这在使用 Xcode 11.3 Sims 13.3 时有效;但是,我刚刚升级了 Xcode,现在它在运行地图功能时崩溃并给出以下错误:
error: Execution was interrupted, reason: internal ObjC exception breakpoint(-8)..The process has been returned to the state before expression evaluation.
如果我放一个断点,我可以看到以下内容:
po alert.staticTexts.allElementsBoundByIndex.count -> returns 3
po alert.staticTexts.allElementsBoundByIndex[0].label -> returns "Allow “X” to use your location?"
po alert.staticTexts.allElementsBoundByIndex[1].label -> returns "Your location is used to find and display nearby X facilities."
po alert.staticTexts.allElementsBoundByIndex[2] -> returns StaticText, {{32.0, 12.0}, {72.5, 16.0}}, label: 'Precise: On'
但是,当我运行以下命令(或在测试期间运行)时,它会失败,但正如您从上面看到的那样,它在该位置确实有一个静态文本元素:
po alert.staticTexts.allElementsBoundByIndex[2].label -> No matches found for Element at index 2 from input {(
StaticText)} error: Execution was interrupted, reason: internal ObjC exception breakpoint(-8)
如果我留在控制台中并再次重新运行相同的调用,它就会起作用:
po alert.staticTexts.allElementsBoundByIndex[2].label -> "Precise: On"
有谁知道导致此错误的原因或在我的测试中如何处理它的解决方案?
【问题讨论】:
标签: ios xcode12 xcuitest xctestcase