我的UITest需要点击一个按钮,UIInteruptionMonitor应该处理它。但是,发生的事情是轻按了按钮,出现并处理了中断,然后尝试再次点击按钮。似乎认为它实际上并没有点击按钮...
我有以下代码:
addUIInterruptionMonitor(withDescription: "Permissions") { alert -> Bool in
let okButton = alert.buttons["OK"]
if okButton.exists {
okButton.tap()
}
return true
}
app.buttons["Enable"].tap()
会发生以下情况:
t = 91.24s Find the "Enable" Button
t = 91.40s Check for interrupting elements affecting "Enable" Button
t = 91.42s Wait for com.apple.springboard to idle
t = 91.85s Found 1 interrupting element:
t = 91.86s Find the "“MyApp” Would Like to Access the Camera" Alert
t = 92.03s "“MyApp” Would Like to Access the Camera" Alert from Application 'com.apple.springboard'
t = 92.03s Invoking UI interruption monitors for "“MyApp” Would Like to Access the Camera" Alert from Application 'com.apple.springboard'
t = 92.03s Invoking Permissions
t = 92.04s Checking existence of `"OK" Button`
t = 92.21s Tap "OK" Button
t = 92.21s Wait for com.apple.springboard to idle
t = 92.50s Find the "OK" Button
t = 92.66s Check for interrupting elements affecting "OK" Button
t = 92.82s Synthesize event
t = 93.14s Wait for com.apple.springboard to idle
t = 93.54s Verifying handling...
t = 93.54s Check for interrupting elements affecting "Enable" Button
t = 93.55s Wait for com.apple.springboard to idle
t = 94.10s Confirmed successful handling of interrupting element
t = 94.10s Synthesize event
t = 95.39s Scroll element to visible
t = 96.55s Failed: Failed to scroll to visible (by AX action) Button, label: 'Enable', error: Error kAXErrorCannotComplete performing AXAction 2003 on element AX element pid: 62934, elementOrHash.elementID: 140664883255456.613
t = 97.57s Retrying `Tap "Enable" Button` (attempt #2)
答案 0 :(得分:0)
这是正常现象。当被系统警报中断时,无法执行预期的操作,因此在成功处理中断后将重试该操作。
通常,您必须在处理程序中检查是否成功处理了中断(例如,找到“确定”按钮并可以点击它),否则,必须返回false。