diff --git a/Classes/KIFUITestActor.h b/Classes/KIFUITestActor.h index c97ae2c00..61309a971 100644 --- a/Classes/KIFUITestActor.h +++ b/Classes/KIFUITestActor.h @@ -435,10 +435,10 @@ static inline KIFDisplacement KIFDisplacementForSwipingInDirection(KIFSwipeDirec #if TARGET_IPHONE_SIMULATOR /*! - @abstract If present, dismisses a system alert with the last button, usually 'Allow'. + @abstract If present, dismisses a system alert with the last button, usually 'Allow'. Returns YES if a dialog was dismissed, NO otherwise. @discussion Use this to dissmiss a location services authorization dialog or a photos access dialog by tapping the 'Allow' button. No action is taken if no alert is present. */ -- (void)acknowledgeSystemAlert; +- (BOOL)acknowledgeSystemAlert; #endif /*! diff --git a/Classes/KIFUITestActor.m b/Classes/KIFUITestActor.m index 1c80abdd4..7a207a779 100644 --- a/Classes/KIFUITestActor.m +++ b/Classes/KIFUITestActor.m @@ -774,8 +774,8 @@ - (void)tapItemAtIndexPath:(NSIndexPath *)indexPath inCollectionViewWithAccessib [self tapItemAtIndexPath:indexPath inCollectionView:collectionView]; } -- (void)acknowledgeSystemAlert { - [UIAutomationHelper acknowledgeSystemAlert]; +- (BOOL)acknowledgeSystemAlert { + return [UIAutomationHelper acknowledgeSystemAlert]; } - (void)tapItemAtIndexPath:(NSIndexPath *)indexPath inCollectionView:(UICollectionView *)collectionView diff --git a/Classes/UIAutomationHelper.h b/Classes/UIAutomationHelper.h index bc1e7559b..822f7219d 100644 --- a/Classes/UIAutomationHelper.h +++ b/Classes/UIAutomationHelper.h @@ -12,7 +12,7 @@ @interface UIAutomationHelper : NSObject -+ (void)acknowledgeSystemAlert; ++ (BOOL)acknowledgeSystemAlert; + (void)deactivateAppForDuration:(NSNumber *)duration; diff --git a/Classes/UIAutomationHelper.m b/Classes/UIAutomationHelper.m index 0f02e2a8d..2c321c77b 100644 --- a/Classes/UIAutomationHelper.m +++ b/Classes/UIAutomationHelper.m @@ -8,6 +8,7 @@ #import "UIAutomationHelper.h" #include +#import @interface UIAElement : NSObject - (void)tap; @@ -15,6 +16,8 @@ - (void)tap; @interface UIAAlert : UIAElement - (NSArray *)buttons; +- (BOOL)isValid; +- (BOOL)isVisible; @end @interface UIAApplication : UIAElement @@ -44,22 +47,23 @@ + (UIAutomationHelper *)sharedHelper return sharedHelper; } -+ (void)acknowledgeSystemAlert { - [[self sharedHelper] acknowledgeSystemAlert]; ++ (BOOL)acknowledgeSystemAlert { + return [[self sharedHelper] acknowledgeSystemAlert]; } + (void)deactivateAppForDuration:(NSNumber *)duration { [[self sharedHelper] deactivateAppForDuration:duration]; } - -- (void)acknowledgeSystemAlert { +- (BOOL)acknowledgeSystemAlert { UIAApplication *application = [[self target] frontMostApp]; - UIAAlert *alert = application.alert; - - if (![alert isKindOfClass:[self nilElementClass]]) { - [[alert.buttons lastObject] tap]; - while (![application.alert isKindOfClass:[self nilElementClass]]) { } - } + UIAAlert* alert = application.alert; + if (![alert isKindOfClass:[self nilElementClass]]) { + [[alert.buttons lastObject] tap]; + while ([alert isValid] && [alert isVisible]) { + } + return YES; + } + return NO; } - (void)deactivateAppForDuration:(NSNumber *)duration { diff --git a/KIF Tests/SystemAlertTests.m b/KIF Tests/SystemAlertTests.m index cda8f8b03..74784dc65 100644 --- a/KIF Tests/SystemAlertTests.m +++ b/KIF Tests/SystemAlertTests.m @@ -24,9 +24,11 @@ - (void)afterEach [tester tapViewWithAccessibilityLabel:@"Test Suite" traits:UIAccessibilityTraitButton]; } -- (void)testAuthorizingLocationServices { - [tester tapViewWithAccessibilityLabel:@"Location Services"]; - [tester acknowledgeSystemAlert]; +- (void)testAuthorizingLocationServicesAndNotificationsScheduling { + [tester tapViewWithAccessibilityLabel:@"Location Services and Notifications"]; + XCTAssertTrue([tester acknowledgeSystemAlert]); + XCTAssertTrue([tester acknowledgeSystemAlert]); + XCTAssertFalse([tester acknowledgeSystemAlert]); } - (void)testAuthorizingPhotosAccess { @@ -35,9 +37,4 @@ - (void)testAuthorizingPhotosAccess { [tester tapViewWithAccessibilityLabel:@"Cancel"]; } -- (void)testNotificationScheduling { - [tester tapViewWithAccessibilityLabel:@"Notifications"]; - [tester acknowledgeSystemAlert]; -} - @end diff --git a/Test Host/SystemAlertViewController.m b/Test Host/SystemAlertViewController.m index 1aa700e81..02b785fde 100644 --- a/Test Host/SystemAlertViewController.m +++ b/Test Host/SystemAlertViewController.m @@ -39,4 +39,9 @@ - (IBAction)requestNotificationScheduling { } } +- (IBAction)requestLocationServicesAndNotificicationsSchedulingAccesses { + [self requestLocationServicesAccess]; + [self requestNotificationScheduling]; +} + @end diff --git a/Test Host/en.lproj/MainStoryboard.storyboard b/Test Host/en.lproj/MainStoryboard.storyboard index 55c8f8c92..076d40d80 100644 --- a/Test Host/en.lproj/MainStoryboard.storyboard +++ b/Test Host/en.lproj/MainStoryboard.storyboard @@ -1,9 +1,9 @@ - + - + @@ -1855,6 +1855,21 @@ Line Break +