Swift3 使用Xcode 9中的Swift 3/Swift 4在XUITEST中处理系统对话框(警报)

Swift3 使用Xcode 9中的Swift 3/Swift 4在XUITEST中处理系统对话框(警报),swift3,swift4,xcode9,xcuitest,Swift3,Swift4,Xcode9,Xcuitest,我想写一个xguitest,在那里我可以得到一个系统对话框/警报。我如何在带有Xcode 9的Swift 3/Swift 4中处理它? 它应该找到警报并单击显示的两个按钮之一。 每次,如果我搜索警报,系统都找不到 XCUIApplication().alerts.element.exists // Will get nothing XCUIApplication().alerts.element.buttons.element(boundBy: 0) // Will get nothing to

我想写一个xguitest,在那里我可以得到一个系统对话框/警报。我如何在带有Xcode 9的Swift 3/Swift 4中处理它? 它应该找到警报并单击显示的两个按钮之一。 每次,如果我搜索警报,系统都找不到

XCUIApplication().alerts.element.exists // Will get nothing
XCUIApplication().alerts.element.buttons.element(boundBy: 0) // Will get nothing too.

您可以尝试使用addUIInterruptionMonitor。下面的示例是当系统警报对话框出现在屏幕上时,点击按钮允许打开系统警报对话框

    addUIInterruptionMonitor(withDescription: "System alert") { (alert) -> Bool in
        if alert.buttons["Allow"].exists {
            alert.buttons["Allow"].tap()
        }
        return true
    }

您可以尝试使用addUIInterruptionMonitor。下面的示例是当系统警报对话框出现在屏幕上时,点击按钮允许打开系统警报对话框

    addUIInterruptionMonitor(withDescription: "System alert") { (alert) -> Bool in
        if alert.buttons["Allow"].exists {
            alert.buttons["Allow"].tap()
        }
        return true
    }
(lldb)po XCUIApplication().alerts.element(边界条件:0)t=274.61s pid 910 t=275.27s的应用程序的快照可访问性层次结构查找:子体匹配类型警报查询链:→查找:目标应用程序0x1702b1100↪︎查找:匹配类型警报的子体↪︎查找:索引为0(lldb)的元素po XCUIApplication().alerts.buttons.count t=300.49s获取与pid为910的应用程序的子体匹配类型按钮t=300.63s快照可访问性层次结构的匹配数t=300.71s查找:子体匹配类型Alert 0
(lldb)po XCUIApplication().alerts.Element(boundBy:0)对于pid 910 t=275.27s的应用程序,t=274.61s快照可访问性层次结构查找:子体匹配类型警报查询链:→查找:目标应用程序0x1702b1100↪︎查找:匹配类型警报的子体↪︎查找:索引0(lldb)处的元素po XCUIApplication().alerts.buttons.count t=300.49s获取以下项的匹配数:子体匹配类型按钮t=300.63s pid 910 t=300.71s的应用程序的快照可访问性层次结构查找:子体匹配类型警报0