@MeGaPk
iOS Программист, 3д печатник

Как правильно пользоваться addUIInterruptionMonitorWithDescription когда системных алертов несколько?

Начал писать ui тесты для своего приложения, и тут возникла с отловом системных алертов, а точнее когда их несколько.. Написал в итоге этот код, первый алерт системный успешно жмёт ОК, второй в итоге не ловит и кидает спустя 6с тайм-аут...

XCUIApplication *app = [[XCUIApplication alloc] init];
app.launchEnvironment = @{
@"isUITest" : YES,
@"withFakeData" : fakeData
};
[app launch];

for (int i = 1; i <= self.possibleSystemAlerts; i++) {
NSLog(@"%d", i);
XCTestExpectation *expectation = [self expectationWithDescription:@"High Expectations"];
id monitor = [self addUIInterruptionMonitorWithDescription:@"Push notifications" handler:^BOOL(XCUIElement *_Nonnull interruptingElement) {
XCUIElement *element = interruptingElement;
XCUIElement *allow = element.buttons[@"Allow"];
XCUIElement *ok = element.buttons[@"OK"];

if ([ok exists]) {
[ok tap];
[expectation fulfill];
return YES;
}

if ([allow exists]) {
[allow forceTap];
[expectation fulfill];
return YES;
}
return NO;
}];
[app tap];
// [app tap];
// [app tap];
[self waitForExpectationsWithTimeout:6.0 handler:^(NSError *error) {
if (error) {
NSLog(@"Timeout Error: %@", error);
}
}];
[self removeUIInterruptionMonitor:monitor];
}
// [self addUIInterruptionMonitorWithDescription:@"Location Dialog" handler:^BOOL(XCUIElement *_Nonnull interruptingElement) {
// XCUIElement *element = interruptingElement;
// [element.buttons[@"OK"] forceTap];
// return YES;
// }];


Уже идеи кончились, весь Гугл перерыл... Надеюсь на вашу помощь, спасибо!
  • Вопрос задан
  • 329 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы