2017-11-29 8 views
1

私はUIテストを実装しています。このアプリケーションは、警告を出すAPI呼び出しを行います(ウィンドウに添付されたUIViewです)。もちろん、これらはランダム/予測不可能です。それらが表示されたら、閉じるボタンをクリックしてそれらを却下しなければなりません。どのようにこれを行うにはどのようなアイデア? UI上で何かが起こったというイベントがありますか?私は解約ボタンが存在するかどうかを確認する0.5秒ごとに実行するスレッドを持つことを考えていました。Xcode UIテストでは、要素が存在するかどうかを繰り返し確認し、そうした要素がある場合はどうすればよいでしょうか?

 DispatchQueue.global().async { 
     while true 
     { 
      DispatchQueue.main.async { 
       if(self.app.buttons["NotificationCloseButton"].exists) 
       { 
        self.app.buttons["NotificationCloseButton"].tap() 
       } 
      } 
      sleep(5) 
     } 
    } 

これに伴う問題は、それがランダムなクラッシュを引き起こすことがある:画面hereに表示する要素のを待つ方法の良い例がありNeither attributes nor error returned

答えて

1

。こちらのリンクから取られたコードの例を次に示します。

let nextGame = self.app.staticTexts["Game 4 - Tomorrow"] 
let exists = NSPredicate(format: "exists == true") 
expectation(for: exists, evaluatedWithObject: nextGame, handler: nil) 

app.buttons["Load More Games"].tap() 

waitForExpectations(timeout: 5, handler: nil) 
XCTAssert(nextGameLabel.exists) 

リンクは、システムのアラートが表示されるのを待つ方法を提供します。

addUIInterruptionMonitor(withDescription: "Location Dialog") { (alert) -> Bool in 
    alert.buttons["Allow"].tap() 
    return true 
} 

app.buttons["Find Games Nearby?"].tap() 
app.tap() // need to interact with the app for the handler to fire 
XCTAssert(app.staticTexts["Authorized"].exists) 
関連する問題