addUIInterruptionMonitor(withDescription:handler:) not working on iOS 10 or 9

后端 未结 3 1875
半阙折子戏
半阙折子戏 2020-12-14 09:16

The following tests works fine on iOS 11. It dismisses the alert asking permissions to use the locations services and then zooms in in the map. On iOS 10 or 9, it does none

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 09:32

    I used the @River2202 solution and it works better than the interruption one. If you decide to use that, I strongly suggest that you use a waiter function. I created this one in order to wait on any kind of XCUIElement to appear:

    Try it!

    // function to wait for an ui element to appear on screen, with a default wait time of 20 seconds
    // XCTWaiter was introduced after Xcode 8.3, which is handling better the timewait, it's not failing the test.  It uses an enum which returns: 'Waiters can be used with or without a delegate to respond to events such as completion, timeout, or invalid  expectation fulfilment.'
    @discardableResult
    func uiElementExists(for element: XCUIElement, timeout: TimeInterval = 20) -> Bool {
        let expectation = XCTNSPredicateExpectation(predicate: NSPredicate(format: "exists == true"), object: element)
        let result = XCTWaiter().wait(for: [expectation], timeout: timeout)
        guard result == .completed else {
            return false
        }
        return true
    }
    

提交回复
热议问题