且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

XCode 7 UI 测试:关闭系统生成的 UIAlertController 不起作用

更新时间:2023-11-13 20:57:16

Xcode 7.1 终于解决了系统警报问题.但是,有两个小问题.

Xcode 7.1 has finally fixed the issue with system alerts. There are, however, two small gotchas.

首先,您需要在显示警报之前设置一个UI Interuption Handler".这是我们告诉框架如何处理出现的警报的方式.

First, you need to set up a "UI Interuption Handler" before presenting the alert. This is our way of telling the framework how to handle an alert when it appears.

其次,在呈现警报后,您必须与界面进行交互.只需点按该应用即可正常工作,但这是必需的.

Second, after presenting the alert you must interact with the interface. Simply tapping the app works just fine, but is required.

addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in
    alert.buttons["Allow"].tap()
    return true
}

app.buttons["Request Location"].tap()
app.tap() // need to interact with the app for the handler to fire

位置对话框"只是一个字符串,用于帮助开发人员识别访问了哪个处理程序,它并不特定于警报类型.我相信从处理程序返回 true 将其标记为完成",这意味着不会再次调用它.

The "Location Dialog" is just a string to help the developer identify which handler was accessed, it is not specific to the type of alert. I believe that returning true from the handler marks it as "complete", which means it won't be called again.