簡體   English   中英

取消位置和通知設置Xcode Ui測試

[英]Dismissing location and notifcation settings Xcode Ui testing

我正在為我的應用編寫UI測試。 我有兩個警報,位置和通知。 我正在努力尋找解決方案以消除這些警報。

目前我正在使用

systemAlertMonitorToken = addUIInterruptionMonitorWithDescription(systemAlertHandlerDescription) { (alert) -> Bool in
    if alert.buttons.matchingIdentifier("OK").count > 0 {
         alert.buttons["OK"].tap()
         return true
     } else {
         return false
     }
}

let notifications = self.app.alerts.element.collectionViews.buttons["OK"]
if notifications.exists {
    notifications.tap()
}

但是,這兩個功能均不允許我關閉警報。

編輯

現在我添加了

  app.buttons["OK"].tap()
    app.tap()

到我的代碼,但這意味着我的測試失敗了,因為XCT在沒有通知立即彈出的情況下立即尋找“確定”按鈕。 我只希望警報OK彈出時(而不是要啟動的第一件事)被關閉。

中斷監視器只會在您下次嘗試與應用程序進行交互時觸發,因此在注冊中斷監視器后,您需要輸入代碼,以在解除警報后執行您想做的任何事情,例如,在UI中點擊另一個按鈕。

當代碼到達您接下來與UI進行交互的部分時,將執行完成處理程序的處理程序,並處理系統警報。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM