如何等待位置警报(系统警报)显示?

Nik*_*sky 0 ios-ui-automation xctest xcode8

我想出了如何解除系统警报,但我无法等待它显示,因为应用程序没有看到系统警报.我尝试使用app.debugDescription和app.alerts.count进行调试,但没有运气.

Mic*_*iec 7

你应该用addUIInterruptionMonitor@Oletha写的.

这里棘手的部分是系统警报按钮不使用辅助功能标识符,因此您必须搜索文本以点击它们.此文本被翻译为您运行模拟器/设备的语言,如果您想要在英语旁边运行多种语言的测试,这可能很难.

您可以使用AutoMate框架来简化此操作.这里有一个如何使用AutoMate处理系统警报的示例:

func locationWhenInUse() {
    let token = addUIInterruptionMonitor(withDescription: "Location") { (alert) -> Bool in
        guard let locationAlert = LocationWhenInUseAlert(element: alert) else {
            XCTFail("Cannot create LocationWhenInUseAlert object")
            return false
        }

        locationAlert.allowElement.tap()
        return true
    }

    // Interruption won't happen without some kind of action.
    app.tap()
    // Wait for given element to appear
    wait(forVisibilityOf: locationPage.requestLabel)
    removeUIInterruptionMonitor(token)
}
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,locationAlert.allowElement.tap()可能是因为AutoMate可以处理iOS模拟器支持的任何语言.

有关如何使用AutoMate处理系统警报的更多示例,请查看:PermissionsTests.swift