iOS UITesting : 使用 addUIInterruptionMonitorWithDescription 自动处理所有系统提示
iOS UITesting : Handle all system prompt automatically with addUIInterruptionMonitorWithDescription
这两本我都看完了
Xcode 7 UI Testing: Dismiss Push and Location alerts
我可以知道以下内容吗?
1) 对于位置,输入"Location Dialog"表示将处理位置提示。它是如何识别的?
2) 如何处理系统提示访问相册或相机?是否有处理程序描述的列表?
这里是 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
1) "Location Dialog" 只是一个 handlerDescription,供您识别您处理的警报。你可以写点别的。
2)你必须使用相同的方法。之后只需点击该应用程序。
这里我使用这部分代码来处理推送通知:
addUIInterruptionMonitorWithDescription("Push notifications") { (alert) -> Bool in
if alert.buttons["OK"].exists {
alert.buttons["OK"].tap()
return true
}
return false
}
app.tap()
干杯
在 xcode 9.1 上,仅当测试设备具有 iOS 11 时才会处理警报。不适用于旧的 iOS 版本,例如 10.3 等。参考:https://forums.developer.apple.com/thread/86989
要处理警报,请使用:
//Use this before the alerts appear. I am doing it before app.launch()
let allowButtonPredicate = NSPredicate(format: "label == 'Always Allow' || label == 'Allow'")
//1st alert
_ = addUIInterruptionMonitor(withDescription: "Allow to access your location?") { (alert) -> Bool in
let alwaysAllowButton = alert.buttons.matching(allowButtonPredicate).element.firstMatch
if alwaysAllowButton.exists {
alwaysAllowButton.tap()
return true
}
return false
}
//Copy paste if there are more than one alerts to handle in the app
这两本我都看完了
Xcode 7 UI Testing: Dismiss Push and Location alerts
我可以知道以下内容吗?
1) 对于位置,输入"Location Dialog"表示将处理位置提示。它是如何识别的?
2) 如何处理系统提示访问相册或相机?是否有处理程序描述的列表?
这里是 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
1) "Location Dialog" 只是一个 handlerDescription,供您识别您处理的警报。你可以写点别的。
2)你必须使用相同的方法。之后只需点击该应用程序。
这里我使用这部分代码来处理推送通知:
addUIInterruptionMonitorWithDescription("Push notifications") { (alert) -> Bool in
if alert.buttons["OK"].exists {
alert.buttons["OK"].tap()
return true
}
return false
}
app.tap()
干杯
在 xcode 9.1 上,仅当测试设备具有 iOS 11 时才会处理警报。不适用于旧的 iOS 版本,例如 10.3 等。参考:https://forums.developer.apple.com/thread/86989
要处理警报,请使用:
//Use this before the alerts appear. I am doing it before app.launch()
let allowButtonPredicate = NSPredicate(format: "label == 'Always Allow' || label == 'Allow'")
//1st alert
_ = addUIInterruptionMonitor(withDescription: "Allow to access your location?") { (alert) -> Bool in
let alwaysAllowButton = alert.buttons.matching(allowButtonPredicate).element.firstMatch
if alwaysAllowButton.exists {
alwaysAllowButton.tap()
return true
}
return false
}
//Copy paste if there are more than one alerts to handle in the app