XCUItest系统警报

问题描述 投票:0回答:1

我正在尝试使用XCUITest和Cucumberish自动化我的应用程序,我无法点击系统警报,例如作为位置和联系人的权限,但我无法点击“允许”或“确定”,它点击“不允许”或“允许”任意“。

这是我在我的步骤定义中尝试使用的代码:

systemAlertMonitorToken = addUIInterruptionMonitor(withDescription: "Location Dialog") { (alert) -> Bool in
        if alert.buttons.matching(identifier: "Allow").count > 0 {
            alert.buttons["Allow"].tap()
            return true
        }
        else if alert.buttons.matching(identifier: "OK").count > 0{
            alert.buttons["OK"].tap()
            return true
        }
        else {
            return false
        }
    }
cucumber xctest xctestcase xcuitest
1个回答
1
投票

我使用此代码点击我的应用中的权限屏幕:

 let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")

 let allowBtn = springboard.buttons[identifier]

 if allowBtn.waitForExistence(timeout: 4) {
      allowBtn.tap()
 }

其中[标识符]为“允许”或“不允许”或您选择的任何选项。

© www.soinside.com 2019 - 2024. All rights reserved.