简体   繁体   中英

how to check alert view displayed in xctest case in xcode

I need to show alert on screen for any validation case and is working fine. But when working with XCTest I am not able to detect if alert is shown. How can I check UIAlertView or UIAlertController in XCTest case in Xcode . please give any suggestions

You can use addUIInterruptionMonitor to handle UIAlertController in XCTest .

let handler = addUIInterruptionMonitor(withDescription: "alert handler") { (alert: XCUIElement) -> Bool in
    let ok = alert.buttons["OK"]
    XCTAssertTrue(ok.exists, "OK button doesn't exist")
    ok.tap()
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM