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!!!