Как отключить оповещения об авторизации системы в XCUITest в iOS 12

У меня все еще есть проблемы с реакцией в моем XCUITest на системные предупреждения, такие как «запрос авторизации для библиотеки фотографий». Я попробовал следующие фрагменты кода. Но ни один из них не работает. Любые идеи?

Монитор прерываний пользовательского интерфейса

addUIInterruptionMonitor(withDescription: "System alert") { (alerts) -> Bool in
    if alert.buttons["OK"].exists {
        alert.buttons["OK"].tap()
    }
    return true
}

XCUIApplication().sheets.buttons["Aufnahme"].firstMatch.tap()

Ожидание с помощью NSPredicate

XCUIApplication().sheets.buttons["Aufnahme"].firstMatch.tap()

let existsPredicate = NSPredicate(format: "exists == true")
let expectation = XCTNSPredicateExpectation(predicate: existsPredicate, object: app.alerts.firstMatch)
let result = XCTWaiter.wait(for: [expectation], timeout: timeout)
if result == .completed {
    app.alerts.firstMatch.tap()
} else {
    print("### TIMEOUT ###")
}

Ожидание существования

XCUIApplication().sheets.buttons["Aufnahme"].firstMatch.tap()
app.alerts.firstMatch.waitForExistence(timeout: 10)

Решение Sprinboard

Это решение основано на сообщении из чешуекрылые. В целом он работает, но кажется довольно медленным (см. мой журнал ниже). В t = 14,51 с я нажимаю кнопку «открыть библиотеку фотографий». Затем в моем приложении появляется системное предупреждение. Но затем все, кажется, зависает примерно на 70 секунд. В t = 78,08 вызывается функция setPermission().

Кто-то сталкивался с подобным поведением?

### OPEN PHOTO LIBRARY
    t =    14.51s Tap "Aufnahmen" Button
    t =    14.51s     Wait for bone.self.TargetShooter to idle
    t =    14.56s     Find the "Aufnahmen" Button
    t =    14.62s         Check for interrupting elements affecting "Aufnahmen" Button
    t =    14.84s     Synthesize event
    t =    14.98s     Wait for bone.self.TargetShooter to idle
    t =    75.08s         App animations complete notification not received, will attempt to continue.
### START AUTHORITATION PROCESS
    t =    75.08s Get number of matches for: Descendants matching type Alert
    t =    75.12s     Snapshot accessibility hierarchy for app with pid 13439
    t =    75.16s     Find: Descendants matching type Alert
### ALLOW SYSTEM ALERT
    t =    75.16s Find the Alert
    t =    75.16s     Snapshot accessibility hierarchy for app with pid 13439
    t =    75.23s     Find: Descendants matching type Alert
    t =    75.23s     Find: Element at index 0
    t =    75.23s Get number of matches for: Descendants matching type Button
    t =    75.29s     Snapshot accessibility hierarchy for app with pid 13439
    t =    75.33s     Find: Descendants matching type Alert
    t =    75.33s     Find: Element at index 0
    t =    75.33s     Find: Descendants matching type Button
    t =    75.33s Checking existence of `Button`
    t =    75.33s     Snapshot accessibility hierarchy for app with pid 13439
    t =    75.39s     Find: Descendants matching type Alert
    t =    75.39s     Find: Element at index 0
    t =    75.39s     Find: Descendants matching type Button
    t =    75.39s     Find: Element at index 1
    t =    75.39s Find the Button
    t =    75.39s     Snapshot accessibility hierarchy for app with pid 13439
    t =    75.45s     Find: Descendants matching type Alert
    t =    75.45s     Find: Element at index 0
    t =    75.45s     Find: Descendants matching type Button
    t =    75.45s     Find: Element at index 1
    t =    75.59s Tap "OK" Button
    t =    75.59s     Wait for com.apple.springboard to idle
    t =    75.65s     Find the "OK" Button
    t =    75.65s         Snapshot accessibility hierarchy for app with pid 13439
    t =    75.72s         Find: Descendants matching type Alert
    t =    75.72s         Find: Element at index 0
    t =    75.72s         Find: Descendants matching type Button
    t =    75.72s         Find: Element at index 1
    t =    75.83s         Check for interrupting elements affecting "OK" Button
    t =    75.88s             Snapshot accessibility hierarchy for app with pid 13439
    t =    75.93s             Find: Descendants matching type Alert
    t =    75.98s     Synthesize event
    t =    76.13s     Wait for com.apple.springboard to idle
### END AUTHORITATION PROCESS

person Morpheus78    schedule 14.04.2019    source источник


Ответы (1)


Вот как это работает в моем коде, попробуйте:

var photoAccessGranted = XCTestExpectation(description: "photo access")


addUIInterruptionMonitor(withDescription: "system permissions") { (alert) -> Bool in
        print("1) addUIInterruptionMonitor:\(alert)")

        if alert.staticTexts["Put here the text that you get in the alert"].exists { // Photo permission
            alert.buttons["OK"].tap()
            self.photoAccessGranted.fulfill()
        }
person nir barzilay    schedule 13.10.2019