1

If the app is installed at the first time, need to allow notification, how can I confirm it? Is someone encountered?

enter image description here

Paul
  • 93
  • 1
  • 4

1 Answers1

2

you should typically be mocking notifications and other data requests in order to prevent the dialogs from coming up. You could also accept the notification manually and re-run your tests. We experimented with using the private UIAutomation framework for this and saw we could achieve this with it. For example, for pressing the left alert button.

@interface SystemAlert : NSObject
- (void)tapLeftButton;
@end

@interface SystemAlert (ForMethodCompletionOnly)
+ (id)localTarget;
- (id)frontMostApp;
- (id)alert;
- (id)buttons;
@end

@implementation SystemAlert

+ (void)load {
  dlopen([@"/Developer/Library/PrivateFrameworks/UIAutomation.framework/UIAutomation" fileSystemRepresentation], RTLD_LOCAL);
}

- (void)tapLeftButton {
  id localTarget = [NSClassFromString(@"UIATarget") localTarget];
  id app = [localTarget frontMostApp];
  id alert = [app alert];
  id button = [[alert buttons] objectAtIndex:0];
  [button tap];
}

@end
khandpur
  • 705
  • 3
  • 12
  • But it seems UIAutomation couldn't work on a non-jail broken device. I have config Setting->Developer->Enable UI Automation, but the app crash and show "UIAutomation is not enabled on this device. UIAutomation must be enabled in Settings." – Paul Mar 28 '16 at 06:23
  • That's weird. I tried it on an iPhone 6s and it worked just fine for me. Could you restart the device, make sure UIAutomation is enabled in settings and try running the tests again? – khandpur Mar 29 '16 at 04:57