iOS UITesting:使用addUIInterruptionMonitorWithDescription自动处理所有系统提示

前端之家收集整理的这篇文章主要介绍了iOS UITesting:使用addUIInterruptionMonitorWithDescription自动处理所有系统提示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经读完了这两个.

Xcode7 | Xcode UI Tests | How to handle location service alert?

Xcode 7 UI Testing: Dismiss Push and Location alerts

我能知道以下情况吗?

1)对于位置,放置“位置对话框”表示它将处理位置提示.它如何识别?

2)如何处理访问图库或相机的系统提示?是否有任何处理程序描述列表?

解决方法

这里是addUIInterruptionMonitorWithDescription的xcode文档.

/*! Adds a handler to the current context. Returns a token that can be used to unregister the handler. Handlers are invoked in the reverse order in which they are added until one of the handlers returns true,indicating that it has handled the alert.
     @param handlerDescription Explanation of the behavior and purpose of this handler,mainly used for debugging and analysis.
     @param handler Handler block for asynchronous UI such as alerts and other dialogs. Handlers should return true if they handled the UI,false if they did not. The handler is passed an XCUIElement representing the top level UI element for the alert.
     */
    public func addUIInterruptionMonitorWithDescription(handlerDescription: String,handler: (XCUIElement) -> Bool) -> NSObjectProtocol

1)“位置对话框”只是一个处理程序描述,用于标识您处理的警报.你可以写别的东西.

2)你必须使用相同的方法.只需点按应用后即可.

在这里,我使用这部分代码来处理推送通知

addUIInterruptionMonitorWithDescription("Push notifications") { (alert) -> Bool in
       if alert.buttons["OK"].exists {
            alert.buttons["OK"].tap()
            return true
       }
       return false
}
app.tap()

干杯

猜你在找的Xcode相关文章