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

Kha*_*inn 4 xcode ios xcode-ui-testing

我已经读完了这两个.

Xcode7 | Xcode UI测试| 如何处理位置服务警报?

Xcode 7 UI测试:解除推送和位置警报

我能知道以下情况吗?

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

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

emo*_*ssi 5

这里的xcode文档addUIInterruptionMonitorWithDescription.

/*! 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
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

干杯