Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Xcode UITest推送通知警报可以';t单击";允许;_Ios_Xcode_Xcode Ui Testing - Fatal编程技术网

Ios Xcode UITest推送通知警报可以';t单击";允许;

Ios Xcode UITest推送通知警报可以';t单击";允许;,ios,xcode,xcode-ui-testing,Ios,Xcode,Xcode Ui Testing,有人有过类似的情况吗?因此,应用程序打开时,会显示推送通知警报,询问用户是否允许接收推送通知,测试单击“不允许”,即使我有以下代码: func testClickSystemAlert(){ let app = XCUIApplication(); XCUIApplication().alerts["“纳豆行” Would Like to Send You Notifications"].buttons["Allow"].tap() } 这是打印输出(x

有人有过类似的情况吗?因此,应用程序打开时,会显示推送通知警报,询问用户是否允许接收推送通知,测试单击“不允许”,即使我有以下代码:

func testClickSystemAlert(){
        let app = XCUIApplication();
        XCUIApplication().alerts["“纳豆行” Would Like to Send You Notifications"].buttons["Allow"].tap()
    }
这是打印输出(xguiapplication().debugDescription)

我建议使用在单元测试中自动授予权限。但这在设备上不起作用,只在模拟器上起作用。

我最终使用了以下方法:

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

它将单击允许按钮

原始答案仅在添加应用程序点击时有效

addUIInterruptionMonitor(withDescription: "YOUR TITLE") { (alert) -> Bool in
                if alert.buttons["OK"].exists {
                    alert.buttons["OK"].tap()
                }
                return true
            }
XCUIApplication().tap() // which is very important!!!
addUIInterruptionMonitor(withDescription: "YOUR TITLE") { (alert) -> Bool in
                if alert.buttons["OK"].exists {
                    alert.buttons["OK"].tap()
                }
                return true
            }
XCUIApplication().tap() // which is very important!!!