Answer the question
In order to leave comments, you need to log in
How to correctly use addUIInterruptionMonitorWithDescription when there are several system alerts?
I started writing ui tests for my application, and then it arose with catching system alerts, or rather when there are several of them .. As a result, I wrote this code, the first system alert successfully presses OK, the second one doesn’t catch it and throws a timeout after 6s .. .
XCUIApplication *app = [[XCUIApplication alloc] init];
app.launchEnvironment = @{
@"isUITest" : YES ,
@"withFakeData" : fakeData
};
[applaunch];
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;
// }];
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question