I'm beginning to experiment with EarlGrey a little bit, having done UI Testing using the XCUITest for some months now. I'm running into the classic problem of being unable to dismiss system alerts, which is strange as it looks as though Google implemented a matcher for system alerts called grey_systemAlertViewShown(). I'm trying to detect system alerts using GREYCondition. Here's what I've tried:
- (void)waitForAndDismissSystemAlertForSeconds:(NSInteger)seconds {
GREYCondition *interactableCondition = [GREYCondition conditionWithName:@"isInteractable" block:^BOOL{
// Fails if element is not interactable
NSError *error;
[[EarlGrey selectElementWithMatcher:grey_systemAlertViewShown()] assertWithMatcher:grey_interactable() error:&error];
if (error) {
return NO;
} else {
NSError *allowButtonError;
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Allow")] assertWithMatcher:grey_notNil() error:&allowButtonError];
if (!allowButtonError) {
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Allow")] performAction:grey_tap()];
}
return YES;
}];
[interactableCondition waitWithTimeout:seconds];
}
I've also tried using addUIInterruptionMonitorWithDescription as described here (but using EarlGrey code to do basically what I am doing above in the interruption monitors): Xcode 7 UI Testing: how to dismiss a series of system alerts in code
Neither approach works. Breakpoints don't fire for the non-error case in my GREYCondition, and the interruption monitor doesn't dismiss my alert either.
Does anybody know if EarlGrey supports dismissing system alerts?