kif-framework / KIF

Keep It Functional - An iOS Functional Testing Framework
Other
6.21k stars 914 forks source link

Dismiss Alertview That is Not Part of the Key Window iOS7 #345

Closed johnryan closed 10 years ago

johnryan commented 10 years ago

My application requires contact access, so I would like to dismiss the alert view that shows when you request contact permission. I have tried finding the view in the window and tapping the screen at the correct point but neither seem to dismiss the alert. I'm not sure if apple provides a way of dismissing this type of system alert.

polymorfiq commented 10 years ago

On iOS 7 I am able to dismiss a UIAlertView by waiting and tapping views with the Accessibility Label that is the same as the Title of the specific button.

    [tester waitForTappableViewWithAccessibilityLabel:@"Ok"];
    [tester tapViewWithAccessibilityLabel:@"Ok"];

I am not yet able to wait for a specific UIAlertView if there are multiple alerts with the same button options such as "Ok"

johnryan commented 10 years ago

This works for UIAlertViews that I create, but it doesn't work for system level alerts. For example, when I request to access the device address book the device pops up an alert that I can't seem to access.

FGoessler commented 10 years ago

Unfortunately there's no 'official' way to bypass or click this alert view away since 'evil' developers could use this method to access your contact or location data in a real applications without your permission. But I found this nice thread (https://groups.google.com/forum/#!topic/kif-framework/xayP4VVBPyg) which explains a valid solution for unit testing purposes. I only used it to avoid the location popup but I think it should also work for contacts.

johnryan commented 10 years ago

Amazing, thanks so much for the tip.

cybertk commented 10 years ago

@johnryan could you please share your solution here, I encounter the same issue.

johnryan commented 10 years ago

@cybertk I just used the solution posted above (https://groups.google.com/forum/#!topic/kif-framework/xayP4VVBPyg). Unfortunately it doesn't seem to work on device, but it works in simulator.

cybertk commented 10 years ago

@johnryan Thank you!, it worked well in simulator.

Benuuu commented 9 years ago

I stumbled across this and the plist workaround posted above didn't work for me. Instead I used the changes introduced in https://github.com/kif-framework/KIF/pull/510

- (void)acknowledgeSystemAlert;

johnryan commented 9 years ago

Interesting, thanks for the heads up @Benuuu