Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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
Swift XCUITest验证ui中断处理程序是否发生_Swift_Iphone_Testing_Xcuitest - Fatal编程技术网

Swift XCUITest验证ui中断处理程序是否发生

Swift XCUITest验证ui中断处理程序是否发生,swift,iphone,testing,xcuitest,Swift,Iphone,Testing,Xcuitest,我对swift和xcuitest很陌生。我最近遇到了addUIInterruptionMonitor,用于处理可能弹出的警报。我想知道的是如何验证警报是否发生以及处理程序是否得到处理。以下面的例子为例 addUIInterruptionMonitorWithDescription(“位置服务”){ (警报)->Bool in 警报。按钮[“允许”]。点击() 返回真值 } 应用程序按钮[“请求位置”]。点击() app.tap()//需要再次与应用程序交互才能触发处理程序 //在此之后,如果处理

我对swift和xcuitest很陌生。我最近遇到了
addUIInterruptionMonitor
,用于处理可能弹出的警报。我想知道的是如何验证警报是否发生以及处理程序是否得到处理。以下面的例子为例

addUIInterruptionMonitorWithDescription(“位置服务”){
(警报)->Bool in
警报。按钮[“允许”]。点击()
返回真值
}
应用程序按钮[“请求位置”]。点击()
app.tap()//需要再次与应用程序交互才能触发处理程序
//在此之后,如果处理程序从未被调用,我希望测试失败

我想测试警报是否真的发生,但据我所知,在我最后一次
tap()
触发警报后,如果警报从未被触发,我的处理程序将不会被调用。我需要测试警报是否确实发生,然后可能会在处理程序的内容中添加一些断言。我似乎已经回答了我自己关于进一步调查的问题。对于使用xcuitest的异步测试,我可以使用一个函数,它将在创建时导致测试等待,直到满足预期,或者在某个超时后失败。因此,我的上述代码变为:

let expectation = XCTestExpectation(description: "Location Service Alert")

let locationMonitorToken = addUIInterruptionMonitorWithDescription("Location Services") { 
  (alert) -> Bool in
  alert.buttons["Allow"].tap()
  expectation.fulfill() // test waits for this before passing
  return true
}

app.buttons["Request Location"].tap()
app.tap() // alert triggered here
wait(for: [expectation], timeout: 3.0)
removeUIInterruptionMonitor(locationMonitorToken)

更新:在触发警报以确保调用处理程序后,忘记输入
等待(for:[预期],超时:3.0)

我似乎已经回答了我自己关于进一步调查的问题。对于使用xcuitest的异步测试,我可以使用一个函数,它将在创建时导致测试等待,直到满足预期,或者在某个超时后失败。因此,我的上述代码变为:

let expectation = XCTestExpectation(description: "Location Service Alert")

let locationMonitorToken = addUIInterruptionMonitorWithDescription("Location Services") { 
  (alert) -> Bool in
  alert.buttons["Allow"].tap()
  expectation.fulfill() // test waits for this before passing
  return true
}

app.buttons["Request Location"].tap()
app.tap() // alert triggered here
wait(for: [expectation], timeout: 3.0)
removeUIInterruptionMonitor(locationMonitorToken)
更新:在触发警报以确保调用处理程序后,忘记将
等待(for:[预期],超时:3.0)
放入